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("Enter an interger N: "))
K=int(input("Enter an interger K: "))
output=0
for number in range(1,N+1):
output+=pow(number,K)
print(output)
Comments
Leave a comment