DEV Community

ETHAN LEONG _
ETHAN LEONG _

Posted on

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) + powerSum(X, N, num + 1)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

If this article connected with you, consider tapping ❤️ or leaving a brief comment to share your thoughts!

Okay