結果
問題 |
No.3038 シャッフルの再現
|
ユーザー |
![]() |
提出日時 | 2025-06-12 14:27:20 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,375 bytes |
コンパイル時間 | 475 ms |
コンパイル使用メモリ | 82,416 KB |
実行使用メモリ | 68,232 KB |
最終ジャッジ日時 | 2025-06-12 14:27:59 |
合計ジャッジ時間 | 2,677 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 1 |
other | RE * 21 |
ソースコード
import sys import math MOD = 10**9 + 7 def factor(n): factors = {} while n % 2 == 0: factors[2] = factors.get(2, 0) + 1 n = n // 2 i = 3 while i * i <= n: while n % i == 0: factors[i] = factors.get(i, 0) + 1 n = n // i i += 2 if n > 1: factors[n] = 1 return factors def generate_divisors(factors_dict): divisors = [1] for p in sorted(factors_dict.keys()): exp = factors_dict[p] current_powers = [p**e for e in range(exp + 1)] new_divisors = [] for d in divisors: for power in current_powers: new_divisors.append(d * power) divisors = list(sorted(set(new_divisors))) return sorted(divisors) def fib_pair(n, mod): if n == 0: return (0, 1) a, b = fib_pair(n // 2, mod) c = (a * (2 * b - a)) % mod d = (a * a + b * b) % mod if n % 2 == 0: return (c, d) else: return (d, (c + d) % mod) def compute_pisano_period(p): if p == 2: return 3 if p == 5: return 20 mod5 = p % 5 if mod5 in (1, 4): candidate = p - 1 else: candidate = 2 * (p + 1) factors = factor(candidate) divisors = generate_divisors(factors) for d in sorted(divisors): if d == 0: continue fn, fn1 = fib_pair(d, p) if fn == 0 and fn1 == 1: return d return candidate def main(): input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 factors = [] for _ in range(N): p = int(input[ptr]) k = int(input[ptr + 1]) ptr += 2 factors.append((p, k)) periods = [] for p, k in factors: if p == 2: if k == 1: pi_pk = 3 elif k == 2: pi_pk = 6 else: pi_pk = 3 * (2 ** (k - 1)) elif p == 5: if k == 1: pi_pk = 20 else: pi_pk = 20 * (5 ** (k - 1)) else: pi_p = compute_pisano_period(p) pi_pk = pi_p * (p ** (k - 1)) periods.append(pi_pk) current_lcm = 1 for p in periods: current_lcm = current_lcm * p // math.gcd(current_lcm, p) print(current_lcm % MOD) if __name__ == "__main__": main()