프로그래밍/HackerRank

[HackerRank][Python3] The Power Sum

snoopybox 2018. 5. 31. 01:12

Problem :

https://www.hackerrank.com/challenges/the-power-sum/problem


My Solution :

#!/usr/bin/env python3

def powerSum(X, N, n):
    a = n**N
    if a == X: return 1
    if a > X: return 0
    return powerSum(X-a, N, n+1) + powerSum(X, N, n+1)


X, N = int(input()), int(input())
result = powerSum(X, N, 1)
print(result)