結果
問題 |
No.1339 循環小数
|
ユーザー |
![]() |
提出日時 | 2021-01-22 15:59:13 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,071 bytes |
コンパイル時間 | 152 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,520 KB |
最終ジャッジ日時 | 2024-12-26 17:33:22 |
合計ジャッジ時間 | 3,640 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 1 |
other | RE * 36 |
ソースコード
#yuki-1339 T = int(input()) candidates = [2*i+1 for i in range(1, 15811)] primelist = [2] p = 3 while p**2 <= 31623: primelist.append(p) candidates = [c for c in candidates if c%p] p = candidates[0] primelist += candidates l = len(primelist) def euler(n): """ nが奇数の時 """ i = 1 ans = n while i < l and primelist[i]**2 <= n: p = primelist[i] if not n%p: ans -= ans//p while not n%p: n //= p i += 1 if n > 1: ans -= ans//n return ans def divlist(n): from collections import defaultdict as ddt d = ddt(int) i = 0 while primelist[i]**2 <= n: p = primelist[i] while not n%p: d[p] += 1 n //= p i += 1 if n > 1: d[n] += 1 ans = {1} for k in d.keys(): plus = set() for x in ans: for ex in range(d[k]): plus.add(x*k**(ex+1)) ans |= plus return sorted(ans) def ediv(N): """ nが奇数の時 """ from collections import defaultdict as ddt d = ddt(int) i = 1 ans = n while i < l and primelist[i]**2 <= n: p = primelist[i] if not n%p: n //= p j = 0 m = p-1 while primelist[j]**2 <= m: p = primelist[j] while not m%p: d[p] += 1 m //= p j += 1 if n > 1: d[n] += 1 while not n%p: n //= p d[p] += 1 i += 1 ans = {1} for k in d.keys(): plus = set() for x in ans: for ex in range(d[k]): plus.add(x*k**(ex+1)) ans |= plus return sorted(ans) for _ in range(T): N = int(input()) #10**9以下 while not N%2: N //= 2 while not N%5: N //= 5 if N == 1: print(1) for d in ediv(N): if pow(10, d, N) == 1: print(d) break