結果
問題 | No.3007 組み紐 |
ユーザー |
![]() |
提出日時 | 2025-03-31 17:35:19 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,791 bytes |
コンパイル時間 | 184 ms |
コンパイル使用メモリ | 82,040 KB |
実行使用メモリ | 70,168 KB |
最終ジャッジ日時 | 2025-03-31 17:36:21 |
合計ジャッジ時間 | 2,918 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 4 |
other | RE * 21 |
ソースコード
import mathimport sysfrom math import gcdfrom random import randintdef is_prime(n):if n < 2:return Falsefor p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]:if n % p == 0:return n == pd = n - 1s = 0while d % 2 == 0:d //= 2s += 1for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:if a >= n:continuex = pow(a, d, n)if x == 1 or x == n - 1:continuefor _ in range(s - 1):x = pow(x, 2, n)if x == n - 1:breakelse:return Falsereturn Truedef pollards_rho(n):if n % 2 == 0:return 2if n % 3 == 0:return 3if n % 5 == 0:return 5while True:c = randint(1, n - 1)f = lambda x: (pow(x, 2, n) + c) % nx, y, d = 2, 2, 1while d == 1:x = f(x)y = f(f(y))d = math.gcd(abs(x - y), n)if d != n:return ddef factor(n):factors = {}for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]:while n % p == 0:factors[p] = factors.get(p, 0) + 1n = n // pif n == 1:return factorsdef _factor(n):if n == 1:returnif is_prime(n):factors[n] = factors.get(n, 0) + 1returnd = pollards_rho(n)_factor(d)_factor(n // d)_factor(n)return factorsn = int(sys.stdin.readline())if n == 1:print(1)else:factors = factor(n)exponents = list(factors.values())current_gcd = exponents[0]for e in exponents[1:]:current_gcd = math.gcd(current_gcd, e)print(current_gcd)