結果
問題 |
No.3038 シャッフルの再現
|
ユーザー |
![]() |
提出日時 | 2025-06-12 15:39:38 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,077 bytes |
コンパイル時間 | 128 ms |
コンパイル使用メモリ | 82,288 KB |
実行使用メモリ | 67,596 KB |
最終ジャッジ日時 | 2025-06-12 15:39:54 |
合計ジャッジ時間 | 2,122 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 1 |
other | RE * 21 |
ソースコード
import sys from collections import defaultdict MOD = 10**9 + 7 def factorize(n): factors = defaultdict(int) while n % 2 == 0: factors[2] += 1 n = n // 2 i = 3 while i * i <= n: while n % i == 0: factors[i] += 1 n = n // i i += 2 if n > 1: factors[n] += 1 return factors def get_divisors(n): if n == 0: return [] factors = factorize(n) divisors = [1] for p, exp in factors.items(): current_length = len(divisors) current_power = 1 for _ in range(exp): current_power *= p for d in divisors[:current_length]: divisors.append(d * current_power) divisors = sorted(divisors) return divisors def fib_pair(n, m): if n == 0: return (0, 1) a, b = fib_pair(n >> 1, m) c = (a * ((2 * b - a) % m)) % m d = (a * a + b * b) % m if n & 1: return (d, (c + d) % m) else: return (c, d) def compute_pisano(p): if p == 2: return 3 if p == 5: return 20 legendre = pow(5, (p - 1) // 2, p) if legendre == 1: candidate = p - 1 else: candidate = 2 * (p + 1) divisors = get_divisors(candidate) for d in divisors: a, b = fib_pair(d, p) if a == 0 and b == 1: return d return candidate def main(): input = sys.stdin.read().split() ptr = 0 n = int(input[ptr]) ptr += 1 max_exponents = defaultdict(int) for _ in range(n): p = int(input[ptr]) ptr += 1 k = int(input[ptr]) ptr += 1 pi_p = compute_pisano(p) factors = factorize(pi_p) if p in factors: factors[p] += (k - 1) else: factors[p] = (k - 1) for q, e in factors.items(): if e > max_exponents[q]: max_exponents[q] = e result = 1 for q, e in max_exponents.items(): result = (result * pow(q, e, MOD)) % MOD print(result) if __name__ == "__main__": main()