結果

問題 No.3038 フィボナッチ数列の周期
ユーザー Ekiben542Ekiben542
提出日時 2024-02-11 16:55:12
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 509 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 848,168 KB
最終ジャッジ日時 2024-02-11 16:55:26
合計ジャッジ時間 12,599 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
77,064 KB
testcase_01 AC 86 ms
112,628 KB
testcase_02 AC 37 ms
53,588 KB
testcase_03 AC 40 ms
59,656 KB
testcase_04 AC 40 ms
59,656 KB
testcase_05 AC 40 ms
59,656 KB
testcase_06 MLE -
testcase_07 AC 525 ms
250,476 KB
testcase_08 AC 467 ms
244,384 KB
testcase_09 AC 365 ms
244,644 KB
testcase_10 AC 687 ms
267,912 KB
testcase_11 AC 353 ms
247,152 KB
testcase_12 AC 572 ms
252,288 KB
testcase_13 AC 561 ms
252,324 KB
testcase_14 AC 599 ms
247,360 KB
testcase_15 AC 1,593 ms
292,216 KB
testcase_16 MLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def fib_modulo(m):
    fib = [0, 1]
    i = 2
    while True:
        fib.append((fib[i-1] + fib[i-2]) % m)
        if fib[i] == fib[1] and fib[i-1] == fib[0]:
            return fib[:-2]
        i += 1

def solve(n, pk):
    MOD = 10**9 + 7
    cycles = [len(fib_modulo(p**k)) for p, k in pk]
    lcm = cycles[0]
    for c in cycles[1:]:
        lcm = lcm * c // math.gcd(lcm, c)
    return lcm % MOD

n = int(input())
pk = [list(map(int, input().split())) for _ in range(n)]
print(solve(n, pk))
0