結果
問題 | No.3038 フィボナッチ数列の周期 |
ユーザー | chocorusk |
提出日時 | 2019-04-01 01:12:16 |
言語 | PyPy3 (7.3.13) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,721 bytes |
コンパイル時間 | 984 ms |
コンパイル使用メモリ | 86,812 KB |
実行使用メモリ | 78,160 KB |
最終ジャッジ日時 | 2023-08-15 11:00:27 |
合計ジャッジ時間 | 8,615 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 67 ms
75,316 KB |
testcase_01 | AC | 75 ms
75,784 KB |
testcase_02 | AC | 67 ms
75,176 KB |
testcase_03 | AC | 73 ms
76,000 KB |
testcase_04 | AC | 69 ms
75,176 KB |
testcase_05 | AC | 71 ms
75,840 KB |
testcase_06 | AC | 77 ms
76,252 KB |
testcase_07 | AC | 109 ms
77,096 KB |
testcase_08 | AC | 123 ms
77,560 KB |
testcase_09 | AC | 116 ms
77,672 KB |
testcase_10 | AC | 113 ms
77,304 KB |
testcase_11 | AC | 118 ms
78,160 KB |
testcase_12 | AC | 121 ms
77,768 KB |
testcase_13 | AC | 109 ms
77,292 KB |
testcase_14 | AC | 116 ms
77,672 KB |
testcase_15 | AC | 110 ms
77,644 KB |
testcase_16 | TLE | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
ソースコード
import math n=int(input()) f=[[1, 1], [1, 0]] MOD=10**9+7 def mul(a, b): ret=[[0, 0], [0, 0]] for i in range(2): for j in range(2): for k in range(2): ret[i][j]+=a[i][k]*b[k][j] return ret def powmod(a, k, mod): ret=[[1, 0], [0, 1]] ap=a while k>0: if k&1: ret=mul(ret, ap) for i in range(2): for j in range(2): ret[i][j]%=mod ap=mul(ap, ap) for i in range(2): for j in range(2): ap[i][j]%=mod k>>=1 return ret ans=1 def lcm(a, b): return a//math.gcd(a, b)*b for i in range(n): p, k=map(int, input().split()) mod=p**k e=(p**(2*k-2))*(p*p-1) x=p-1 fac=[] for j in range(2, x+1): if j*j>x: break if x%j==0: t=0 while x%j==0: x//=j t+=1 fac.append([j, t]) if x>1: fac.append([x, 1]) x=p+1 for j in range(2, x+1): if j*j>x: break if x%j==0: t=0 while x%j==0: x//=j t+=1 if j==2: fac[0][1]+=t else: fac.append([j, t]) if x>1: fac.append([x, 1]) for j in range(2*k-2): e//=p fp=powmod(f, e, mod) if fp[0][0]==1 and fp[1][0]==0: continue e*=p break for q in fac: for j in range(q[1]): e//=q[0] fp=powmod(f, e, mod) if fp[0][0]==1 and fp[1][0]==0: continue e*=q[0] break ans=lcm(ans, e) print(ans%MOD)