Recursion Power Sum

def powerSum(X, N, num=1):
power = num ** N

if power > X:
return 0 # too big, can’t continue
elif power == X:
return 1 # exact match found
else:
# either include this number or skip it
return powerSum(X – power, N, num + 1) +…


This content originally appeared on DEV Community and was authored by ETHAN LEONG _

def powerSum(X, N, num=1):
power = num ** N

if power > X:
    return 0  # too big, can't continue
elif power == X:
    return 1  # exact match found
else:
    # either include this number or skip it
    return powerSum(X - power, N, num + 1) + powerSum(X, N, num + 1)


This content originally appeared on DEV Community and was authored by ETHAN LEONG _


Print Share Comment Cite Upload Translate Updates
APA

ETHAN LEONG _ | Sciencx (2025-03-27T15:59:40+00:00) Recursion Power Sum. Retrieved from https://www.scien.cx/2025/03/27/recursion-power-sum/

MLA
" » Recursion Power Sum." ETHAN LEONG _ | Sciencx - Thursday March 27, 2025, https://www.scien.cx/2025/03/27/recursion-power-sum/
HARVARD
ETHAN LEONG _ | Sciencx Thursday March 27, 2025 » Recursion Power Sum., viewed ,<https://www.scien.cx/2025/03/27/recursion-power-sum/>
VANCOUVER
ETHAN LEONG _ | Sciencx - » Recursion Power Sum. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/03/27/recursion-power-sum/
CHICAGO
" » Recursion Power Sum." ETHAN LEONG _ | Sciencx - Accessed . https://www.scien.cx/2025/03/27/recursion-power-sum/
IEEE
" » Recursion Power Sum." ETHAN LEONG _ | Sciencx [Online]. Available: https://www.scien.cx/2025/03/27/recursion-power-sum/. [Accessed: ]
rf:citation
» Recursion Power Sum | ETHAN LEONG _ | Sciencx | https://www.scien.cx/2025/03/27/recursion-power-sum/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.