Sum of K powers
Write a program to print the sum of the Kth power of the first N natural numbers.
Input
The first line of input is an integer N. The second line of input is an integer K.
Explanation
In the given example, the sum of first
5 natural numbers power of 3.The sum should be 13 + 23 + 33 + 43 + 53
Therefore, the output should be
225.
Sample Input 1
5
3
Sample Output 1
225
Sample Input 2
2
8
Sample Output 2
257
N=int(input())
K=int(input())
sumResult=0
for number in range(1,N+1):
sumResult+=pow(number,K)
print(sumResult)
Comments
Leave a comment