Playing with digits

Language: Python

Task:

When two positive integers are given (n and p) the challenge was to find if the integer k exists, such that the sum of the digits of n each to the power of the successive powers of p is equal to k*n. It shall return -1 if there is no positive integer k.

Example: 695, 2 = 6**2 + 6**3 + 6**4 = 1390. 1390/695 = 2 so it returns 2.

Parameters:

  • n and p will always be strict positive integers