PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
https://www.sololearn.com/Discuss/3289470/?ref=app
my question is listed below please find answer
Problem Statement: Alex is exploring a series and she came across a special series, in which f(N)=f(N-1)*(N-1)+(N-2)*(N-2) mod 47 where f(0) = 1, f(1) = 1 Your task is to help Alex find and return an integer value, representing the Nth number in this special series Note: Return the output modulo 47. Input Specification: input1: An integer value N. Output Specification: Return an integer value, representing the Nth number in this special series. Sample Input: 4 Sample Output: 29
"""
l=[1,1]
pairs = [(1,1)]
f=lambda x,y:(x**2 +y**2)%47
testlist = [1,1]
for i in range(250):
testlist.append(f(testlist[-1],testlist[-2]))
i = 0
while True:
i+=1
nextValue = f(l[-1],l[-2])
l.append(nextValue )
nextPair =l[-2],l[-1]
# here the first period stops..
if nextPair in pairs:
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run