Sum of the series
Write a program to find the sum
S of the series where S = x - x^3 + x^5 + ....... upto N terms.
Input
The first line of input is an integer
X. The second line of input is an integer N.
Explanation
If we take
X value as 2 in the series upto 5 terms.
Then the series is 2 - 23 + 25 - 27 + 29
So, the output should be
410.
Sample Input 1
2
5
Sample Output 1
410
Sample Input 2
3
2
Sample Output 2
-24
x = int(input())
N = int(input())
S = 0
k = 1
for i in range(N):
S += k*(x**(2*i+1))
k *= -1
print(S)
Comments
Leave a comment