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
# modified from code by Jan
'''
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
'''
def f(n):
if n==0 or n==1:
return 1
arr = [1,1]
for i in range(2, n+1):
arr.append(
(arr[-1]**2+arr[i-2]**2)%47)
#arr gets really long!
#print(f'{len(arr) = }')
return arr[-1]
print("f(1000000) =", f(1000000))
for i in range(0, 51):
print(f"f({i}) = {f(i)}")
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run