結果

問題 No.1339 循環小数
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-02-12 13:47:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 769 bytes
コンパイル時間 632 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 130,668 KB
最終ジャッジ日時 2023-09-26 13:03:48
合計ジャッジ時間 10,148 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,512 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 75 ms
76,196 KB
testcase_16 AC 75 ms
76,176 KB
testcase_17 AC 76 ms
76,396 KB
testcase_18 AC 78 ms
76,132 KB
testcase_19 WA -
testcase_20 AC 74 ms
76,268 KB
testcase_21 AC 397 ms
129,992 KB
testcase_22 AC 400 ms
128,468 KB
testcase_23 AC 400 ms
129,048 KB
testcase_24 AC 412 ms
127,704 KB
testcase_25 AC 399 ms
130,668 KB
testcase_26 AC 400 ms
128,804 KB
testcase_27 AC 396 ms
129,332 KB
testcase_28 AC 407 ms
129,572 KB
testcase_29 WA -
testcase_30 AC 395 ms
128,824 KB
testcase_31 AC 414 ms
128,760 KB
testcase_32 AC 411 ms
129,696 KB
testcase_33 AC 396 ms
127,624 KB
testcase_34 AC 211 ms
100,992 KB
testcase_35 AC 448 ms
126,336 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

# baby-step-giant-step
# (a**k)%mod=1となる最小のkを返す
def bsgs(a,mod):
  c=int(mod**0.5)+1
  d={}
  # baby-step
  now=1
  for i in range(c):
    d[now]=i
    now*=a
    now%=n
    if now==1:return i+1
  # giant-step
  now=1
  gs=pow(a,c,n)
  for i in range(c):
    pre=now
    now*=gs
    now%=n
    if now in d:return (i+1)*c-d[now]

# now=1からはじめ、以下を繰り返す。
# ・now%=n
# ・now*=10
# 過去に一度出たnowが再び出たらそこから循環する。nowの取りうる値は0~n-1なので循環は高々n個から成る。
# 10**k=1 (mod n)となるkで循環する
# baby-step-giant-step
if __name__=='__main__':
  t=int(input())
  cases=[int(input()) for _ in range(t)]
  for n in cases:
    retb=bsgs(10,n)
    print(retb)
0