Sum of Consecutive Powers
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
0 <= n <= 1000 <= p <= 5
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Math problems
- Sum of DivisorsBeginner
- Sum of MultiplesBeginner
- Type of TriangleBeginner
- Add Minutes to a ClockEasy
- Add StringsEasy
- Add Two Numbers in Base KEasy
- Angle Between Clock HandsEasy
- Area of Two RectanglesEasy