結果
問題 | No.1339 循環小数 |
ユーザー | persimmon-persimmon |
提出日時 | 2021-02-12 13:22:15 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,396 bytes |
コンパイル時間 | 336 ms |
コンパイル使用メモリ | 87,240 KB |
実行使用メモリ | 87,860 KB |
最終ジャッジ日時 | 2023-09-26 12:47:49 |
合計ジャッジ時間 | 7,328 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
71,784 KB |
testcase_01 | AC | 81 ms
76,680 KB |
testcase_02 | AC | 79 ms
76,848 KB |
testcase_03 | AC | 80 ms
76,772 KB |
testcase_04 | AC | 80 ms
76,584 KB |
testcase_05 | AC | 80 ms
76,584 KB |
testcase_06 | AC | 79 ms
76,520 KB |
testcase_07 | AC | 79 ms
76,884 KB |
testcase_08 | AC | 80 ms
76,924 KB |
testcase_09 | AC | 79 ms
76,824 KB |
testcase_10 | AC | 79 ms
76,688 KB |
testcase_11 | AC | 98 ms
76,724 KB |
testcase_12 | AC | 97 ms
76,776 KB |
testcase_13 | AC | 93 ms
76,860 KB |
testcase_14 | AC | 92 ms
76,580 KB |
testcase_15 | AC | 93 ms
76,800 KB |
testcase_16 | AC | 94 ms
76,672 KB |
testcase_17 | AC | 98 ms
76,796 KB |
testcase_18 | AC | 92 ms
77,128 KB |
testcase_19 | AC | 91 ms
76,568 KB |
testcase_20 | AC | 90 ms
76,984 KB |
testcase_21 | TLE | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
ソースコード
def main1(n): # now=1からはじめ、以下を繰り返す。 # ・now%=n # ・now*=10 # 過去に一度出たnowが再び出たらそこから循環する。nowの取りうる値は0~n-1なので循環は高々n個から成る。 # なのでn回操作を行った後のnowは必ず循環に入る。n回操作を行った後のnowから探索を開始してよい。 # このnowをv0とする。 # baby-step-giant-stepでできそう。 # 0.c=int(n**0.5)+1とする。 # 1.v0からc-1回操作を行う(baby-step)。この時v0が出てきたら循環するので操作は終了。 # 2.v0にc回操作を一回にまとめた操作を行う(giant-step)。1で出た値が出たら循環する。この操作は必ず終わる。 # 合計O(√n) # n未満の整数は、c=int(n**0.5)+1として、ある整数a,b(0<=a,b<c)があり、a*c+bと一意に表すことができる。 # aがgiant-step、bがbaby-step v0=pow(10,n,n) c=int(n**0.5)+1 d={} # baby-step now=v0 for i in range(c): d[now]=i now*=10 now%=n if now==v0:return i+1 # giant-step now=v0 for i in range(c): pre=now for _ in range(c): now*=10 now%=n if now in d:return (i+1)*c-d[now] return n if __name__=='__main__': t=int(input()) cases=[int(input()) for _ in range(t)] for n in cases: ret1=main1(n) print(ret1)