結果
問題 | No.1339 循環小数 |
ユーザー |
|
提出日時 | 2021-01-15 22:15:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 133 ms / 2,000 ms |
コード長 | 1,158 bytes |
コンパイル時間 | 148 ms |
コンパイル使用メモリ | 82,188 KB |
実行使用メモリ | 66,108 KB |
最終ジャッジ日時 | 2024-11-26 15:47:45 |
合計ジャッジ時間 | 3,694 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 36 |
ソースコード
# 参考:http://www2r.biglobe.ne.jp/~kosanhp/math/junkan.pdffrom math import gcdlcm = lambda a, b: a * b // gcd(a, b)def make_divisors(n):for i in range(1, int(n ** 0.5) + 1):if n % i == 0:yield iif i != n // i:yield n // idef factorization(n):arr = dict()temp = nfor i in range(2, int(-(-n ** 0.5 // 1)) + 1):if temp % i == 0:cnt = 0while temp % i == 0:cnt += 1temp //= iarr[i] = cntif temp != 1:arr[temp] = 1if not arr and n != 1:arr[n] = 1return arrdef solve(N):while not N % 2:N //= 2while not N % 5:N //= 5if N == 1:return 1res = 1for p, idx in factorization(N).items():l = Nfor d in make_divisors(p - 1):if pow(10, d, p) == 1:l = min(l, d)e = (2 if p in (3, 487) else 1)if idx > e:l *= p ** (idx - e)res = lcm(res, l)return resT = int(input())for _ in range(T):print(solve(int(input())))