結果

問題 No.1339 循環小数
ユーザー googol_S0googol_S0
提出日時 2021-01-15 22:15:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 937 bytes
コンパイル時間 418 ms
コンパイル使用メモリ 87,276 KB
実行使用メモリ 76,884 KB
最終ジャッジ日時 2023-08-17 17:29:48
合計ジャッジ時間 5,688 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,804 KB
testcase_01 AC 80 ms
76,404 KB
testcase_02 AC 80 ms
75,952 KB
testcase_03 AC 82 ms
76,148 KB
testcase_04 AC 81 ms
75,632 KB
testcase_05 AC 79 ms
75,920 KB
testcase_06 AC 80 ms
76,396 KB
testcase_07 AC 79 ms
76,020 KB
testcase_08 AC 80 ms
75,988 KB
testcase_09 AC 81 ms
76,640 KB
testcase_10 AC 80 ms
75,764 KB
testcase_11 AC 87 ms
76,620 KB
testcase_12 AC 85 ms
76,584 KB
testcase_13 AC 85 ms
76,756 KB
testcase_14 AC 87 ms
76,584 KB
testcase_15 AC 86 ms
76,452 KB
testcase_16 AC 86 ms
76,840 KB
testcase_17 AC 86 ms
76,692 KB
testcase_18 AC 91 ms
76,856 KB
testcase_19 AC 86 ms
76,748 KB
testcase_20 AC 86 ms
76,732 KB
testcase_21 AC 127 ms
76,620 KB
testcase_22 AC 132 ms
76,736 KB
testcase_23 AC 130 ms
76,464 KB
testcase_24 AC 126 ms
76,352 KB
testcase_25 AC 131 ms
76,600 KB
testcase_26 AC 135 ms
76,744 KB
testcase_27 AC 133 ms
76,744 KB
testcase_28 AC 133 ms
76,884 KB
testcase_29 AC 123 ms
76,548 KB
testcase_30 AC 126 ms
76,716 KB
testcase_31 AC 157 ms
76,584 KB
testcase_32 AC 160 ms
76,460 KB
testcase_33 AC 133 ms
76,712 KB
testcase_34 AC 117 ms
76,684 KB
testcase_35 AC 170 ms
76,664 KB
testcase_36 AC 133 ms
76,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
def lcm(X):
  r=X[0]
  for i in range(len(X)):
    r=r*X[i]//gcd(r,X[i])
  return r

def f(x):
  r=[]
  for i in range(2,int(x**0.5)+1):
    if x%i==0:
      r.append([i,0])
      while x%i==0:
        x//=i
        r[-1][1]+=1
  if x>1:
    r.append([x,1])
  return r

def d(x):
  r=[]
  for i in range(1,int(x**0.5)+1):
    if x%i==0:
      r.append(i)
      if i*i!=x:
        r.append(x//i)
  r.sort()
  return r

def l(x):
  if len(x)==1:
    if x[0][0]==2:
      if x[0][1]<=2:
        return x[0][1]
      else:
        return 2**(x[0][1]-2)
    else:
      return (x[0][0]**(x[0][1]-1))*(x[0][0]-1)
  return lcm([l([x[i]]) for i in range(len(x))])

def solve():
  N=int(input())
  while N%2==0:
    N//=2
  while N%5==0:
    N//=5
  if N==1:
    print(1)
    return 0
  X=d(l(f(N)))
  for j in range(len(X)):
    if pow(10,X[j],N)==1:
      print(X[j])
      return 0

for i in range(int(input())):
  solve()
0