-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforceArray.py
More file actions
38 lines (34 loc) · 725 Bytes
/
forceArray.py
File metadata and controls
38 lines (34 loc) · 725 Bytes
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
29
30
31
32
33
34
35
36
37
38
def solve(a,b,n,mod):
arr=[a,b]
dict={}
lis=[]
dict[a]=1
try:
d=dict[b]
dict[b]=d+1
except:
dict[b]=1
lis.append(b)
for i in range(2,n):
temp=(arr[i-1]+arr[i-2])%mod
try:
d=dict[temp]
dict[temp]= d+1
except:
dict[temp]=1
lis.append(temp)
arr.append(temp)
print(arr)
result=0
for i in range(len(lis)):
result+=dict[lis[i]]**2
print(result)
if __name__ == "__main__":
t=int(input())
for _ in range(t):
a,b,n,mod = input().split()
a=int(a)
b=int(b)
n=int(n)
mod=int(mod)
solve(a,b,n,mod)