Some numbers have funny properties. For example:

> 89 --> 8¹ + 9² = 89 * 1

> 695 --> 6² + 9³ + 5⁴= 1390 = 695 * 2

> 46288 --> 4³ + 6⁴+ 2⁵ + 8⁶ + 8⁷ = 2360688 = 46288 * 51

Given a positive integer n written as abcd... (a, b, c, d... being digits) and a positive integer p 
- we want to find a positive integer k, if it exists, such as the sum of the digits of n taken to the successive powers of p is equal to k * n. 

In other words:

> Is there an integer k such as : (a ^ p + b ^ (p+1) + c ^(p+2) + d ^ (p+3) + ...) = n * k

If it is the case we will return k, if not return -1.

**Note**: n and p will always be given as strictly positive integers.

```python
dig_pow(89, 1) should return 1 since 8¹ + 9² = 89 = 89 * 1
dig_pow(92, 1) should return -1 since there is no k such as 9¹ + 2² equals 92 * k
dig_pow(695, 2) should return 2 since 6² + 9³ + 5⁴= 1390 = 695 * 2
dig_pow(46288, 3) should return 51 since 4³ + 6⁴+ 2⁵ + 8⁶ + 8⁷ = 2360688 = 46288 * 51
```

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Mathematics

Starter code: def dig_pow(n, p):
	

Solutions:
def dig_pow(n, p):
	s = 0
	for (i, c) in enumerate(str(n)):
		s += pow(int(c), p + i)
	return s / n if s % n == 0 else -1


def dig_pow(n, p):
	(k, fail) = divmod(sum((int(d) ** (p + i) for (i, d) in enumerate(str(n)))), n)
	return -1 if fail else k


def dig_pow(n, p):
	t = sum((int(d) ** (p + i) for (i, d) in enumerate(str(n))))
	return t // n if t % n == 0 else -1


def dig_pow(n, p):
	n_list = [int(i) for i in str(n)]
	n_sum = 0
	p_i = p
	for n_i in n_list:
		n_sum = n_sum + n_i ** p_i
		p_i = p_i + 1
	if n_sum % n == 0:
		return n_sum / n
	else:
		return -1


def dig_pow(n, p):
	sum = 0
	for c in str(n):
		sum += int(c) ** p
		p += 1
	if sum % n == 0:
		return sum / n
	else:
		return -1


def dig_pow(n, p):
	digit_power = sum((int(x) ** pw for (pw, x) in enumerate(str(n), p)))
	if digit_power % n == 0:
		return digit_power / n
	return -1


def dig_pow(n, p):
	(k, r) = divmod(sum((int(l) ** (p + i) for (i, l) in enumerate(str(n)))), n)
	return -1 if r else k