FunctionRacerProblemsRace

Sum of Consecutive Powers

BeginnerMathPython, JavaScript, TypeScript, Java, C++

Return 1p + 2p + ... + n**p, the sum of the p-th powers of the whole numbers from 1 to n. For n = 0 the sum is 0.

Example 1

n 3
p 2
returns 14

1 + 4 + 9 = 14.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems