結果
| 問題 |
No.3038 シャッフルの再現
|
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 14:28:34 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,500 bytes |
| コンパイル時間 | 317 ms |
| コンパイル使用メモリ | 82,364 KB |
| 実行使用メモリ | 67,776 KB |
| 最終ジャッジ日時 | 2025-06-12 14:28:43 |
| 合計ジャッジ時間 | 2,327 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 1 |
| other | RE * 21 |
ソースコード
import sys
from math import gcd
from collections import defaultdict
MOD = 10**9 + 7
def factor(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 generate_divisors(factors):
divisors = [1]
for p in factors:
exponents = [p**e for e in range(1, factors[p] + 1)]
new_divisors = []
for d in divisors:
for exp in exponents:
new_divisors.append(d * exp)
divisors += new_divisors
return sorted(divisors)
def fib_pair(n, mod):
if n == 0:
return (0, 1)
a, b = fib_pair(n >> 1, mod)
c = a * (2 * b - a) % mod
d = (a * a + b * b) % mod
if n & 1:
return (d, (c + d) % mod)
else:
return (c, d)
def compute_pisano_period(p):
if p == 2:
return 3
if p == 5:
return 20
mod5 = p % 5
if mod5 in (1, 4):
m = p - 1
else:
m = 2 * (p + 1)
factors = factor(m)
divisors = generate_divisors(factors)
for d in divisors:
Fd, Fd_plus_1 = fib_pair(d, p)
if Fd % p == 0 and Fd_plus_1 % p == 1:
return d
return m # fallback
def compute_period_factors(p, k):
if p == 2:
if k == 1:
return {3: 1}
elif k == 2:
return {2: 1, 3: 1}
else:
return {2: k - 1, 3: 1}
if p == 5:
factors = {2: 2, 5: 1}
factors[5] += (k - 1)
return factors
d = compute_pisano_period(p)
Fd_mod, _ = fib_pair(d, p * p)
if Fd_mod % (p * p) == 0:
e = k
else:
e = k - 1
d_factors = factor(d)
d_factors[p] = d_factors.get(p, 0) + e
return d_factors
def main():
n = int(sys.stdin.readline())
input_factors = []
for _ in range(n):
p, k = map(int, sys.stdin.readline().split())
input_factors.append((p, k))
global_factors = defaultdict(int)
for p, k in input_factors:
period_factors = compute_period_factors(p, k)
for q in period_factors:
e = period_factors[q]
if e > global_factors[q]:
global_factors[q] = e
result = 1
for q in global_factors:
result = (result * pow(q, global_factors[q], MOD)) % MOD
print(result)
if __name__ == "__main__":
main()
gew1fw