結果
| 問題 |
No.1339 循環小数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-15 22:15:53 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 497 ms / 2,000 ms |
| コード長 | 1,119 bytes |
| コンパイル時間 | 274 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-11-26 15:49:23 |
| 合計ジャッジ時間 | 5,536 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 36 |
ソースコード
# 参考:http://www2r.biglobe.ne.jp/~kosanhp/math/junkan.pdf
from math import lcm
def make_divisors(n):
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
yield i
if i != n // i:
yield n // i
def factorization(n):
arr = dict()
temp = n
for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr[i] = cnt
if temp != 1:
arr[temp] = 1
if not arr and n != 1:
arr[n] = 1
return arr
def solve(N):
while not N % 2:
N //= 2
while not N % 5:
N //= 5
if N == 1:
return 1
res = 1
for p, idx in factorization(N).items():
l = N
for 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 res
T = int(input())
for _ in range(T):
print(solve(int(input())))