Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dig_pow(n, p):
- print("n = " + str(n) + ", p = " + str(p))
- nStr = str(n)
- digits = [int(nStr[i]) for i in range(len(nStr))]
- # Checking
- flag = False
- number2 = 0
- for i in range(1, len(digits) + 1):
- number2 += digits[i-1] ** (p+i-1)
- print("number2 = " + str(number2))
- if number2 % n != 0:
- print("number2 % n != 0")
- return -1
- else:
- result = int(number2 / n)
- print("number2 / n = " + str(result))
- return result
- # MAIN FUNCTION
- print(dig_pow(89, 1))
- print()
- print(dig_pow(92, 1))
- print()
- print(dig_pow(256, 2))
- print()
- print(dig_pow(695, 2))
- print()
- print(dig_pow(46288, 3))
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement