Question #224585

X = int(input())
N = int(input())
M = 1 + 2*(N-1)
list1 = []
i = 1
j = 0
k = 0
while i <= M:
 list1.append(X**i)
 i = i + 2


for s in list1:
 if (list1.index(s))%2 == 0:
  j = j + s
 else:
  k = k - s
print(j+k)


In this python program it has three test cases, in this three test cases two test cases are getting expected output and third test case are not getting expected output. Please give me expexted output for three test cases. Thank you !

Question url :-

https://drive.google.com/file/d/15oYX0I0vkskebiNz7Wg80SdkZ-MzHTrg/view?usp=sharing

Test case 1

Input

2

5

Output

410

Test case 2

Input

3

2

Output

-24

Test case 3

Input

1

5

Output

1


Expert's answer

X = int(input())
N = int(input())
sumResult=0
ex=1
for x in range(0,N):
    if x%2==0:
        sumResult+=pow(X,ex)
    else:
        sumResult-=pow(X,ex)
    ex+=2


print(sumResult)





LATEST TUTORIALS
APPROVED BY CLIENTS