結果
問題 | No.1339 循環小数 |
ユーザー | 👑 rin204 |
提出日時 | 2022-10-31 23:28:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 103 ms / 2,000 ms |
コード長 | 2,141 bytes |
コンパイル時間 | 441 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 76,416 KB |
最終ジャッジ日時 | 2024-07-08 11:03:01 |
合計ジャッジ時間 | 4,153 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
52,480 KB |
testcase_01 | AC | 55 ms
61,696 KB |
testcase_02 | AC | 54 ms
61,952 KB |
testcase_03 | AC | 51 ms
62,848 KB |
testcase_04 | AC | 50 ms
61,824 KB |
testcase_05 | AC | 49 ms
61,952 KB |
testcase_06 | AC | 50 ms
62,080 KB |
testcase_07 | AC | 50 ms
61,568 KB |
testcase_08 | AC | 50 ms
62,080 KB |
testcase_09 | AC | 56 ms
62,208 KB |
testcase_10 | AC | 52 ms
62,080 KB |
testcase_11 | AC | 65 ms
68,224 KB |
testcase_12 | AC | 65 ms
68,352 KB |
testcase_13 | AC | 69 ms
69,632 KB |
testcase_14 | AC | 68 ms
68,096 KB |
testcase_15 | AC | 65 ms
68,608 KB |
testcase_16 | AC | 68 ms
68,992 KB |
testcase_17 | AC | 63 ms
67,456 KB |
testcase_18 | AC | 65 ms
68,480 KB |
testcase_19 | AC | 65 ms
67,456 KB |
testcase_20 | AC | 70 ms
68,992 KB |
testcase_21 | AC | 98 ms
76,288 KB |
testcase_22 | AC | 100 ms
75,904 KB |
testcase_23 | AC | 92 ms
76,032 KB |
testcase_24 | AC | 100 ms
76,416 KB |
testcase_25 | AC | 100 ms
76,288 KB |
testcase_26 | AC | 89 ms
75,776 KB |
testcase_27 | AC | 100 ms
76,416 KB |
testcase_28 | AC | 95 ms
76,288 KB |
testcase_29 | AC | 99 ms
76,032 KB |
testcase_30 | AC | 97 ms
76,416 KB |
testcase_31 | AC | 98 ms
75,904 KB |
testcase_32 | AC | 99 ms
75,904 KB |
testcase_33 | AC | 95 ms
76,032 KB |
testcase_34 | AC | 88 ms
75,904 KB |
testcase_35 | AC | 64 ms
67,584 KB |
testcase_36 | AC | 103 ms
76,288 KB |
ソースコード
from math import gcd def isprime(n): if n <= 1: return False elif n == 2: return True elif n % 2 == 0: return False A = [2, 325, 9375, 28178, 450775, 9780504, 1795265022] s = 0 d = n - 1 while d % 2 == 0: s += 1 d >>= 1 for a in A: if a % n == 0: return True x = pow(a, d, n) if x != 1: for t in range(s): if x == n - 1: break x = x * x % n else: return False return True def pollard(n): if n % 2 == 0: return 2 if isprime(n): return n f = lambda x:(x * x + 1) % n step = 0 while 1: step += 1 x = step y = f(x) while 1: p = gcd(y - x + n, n) if p == 0 or p == n: break if p != 1: return p x = f(x) y = f(f(y)) def primefact(n): if n == 1: return [] p = pollard(n) if p == n: return [p] left = primefact(p) right = primefact(n // p) left += right return sorted(left) def divisor_lst(n): if n == 1: return [1] primes = primefact(n) primes.append(primes[-1] + 1) bef = primes[0] cnt = 0 ret = [1] for p in primes: if p == bef: cnt += 1 else: times = bef le = len(ret) for _ in range(cnt): for i in range(le): ret.append(ret[i] * times) times *= bef bef = p cnt = 1 ret.sort() return ret def solve(n): while n % 2 == 0: n //= 2 while n % 5 == 0: n //= 5 if n == 1: return 1 primes = set(primefact(n)) N = n for p in primes: n *= p - 1 n //= p divs = divisor_lst(n) for d in divs: x = pow(10, d, N) - 1 if x == 0: return d for _ in range(int(input())): ans = solve(int(input())) print(ans)