結果
問題 |
No.1339 循環小数
|
ユーザー |
|
提出日時 | 2023-11-19 21:23:51 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,486 bytes |
コンパイル時間 | 906 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 15,408 KB |
最終ジャッジ日時 | 2024-09-26 06:24:40 |
合計ジャッジ時間 | 7,867 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 |
other | WA * 20 RE * 16 |
ソースコード
# d = int(input("分母 d: ")) # print("1 /", d, "を求めます。") # # 例外処理 # if d <= 0: # print("条件を満たさない入力です。d>=1である必要があります。") # exit() # elif d == 1: # print("1 / 1 = 1 です。") # exit() t = int(input()) a = [int(input()) for _ in range(t)] for d in a: done = False x = 1 counter = 1 isRecurringDecimal = False cycleLength = 0 quotientList = [] remainderList = [-1] * d remainderList[1] = 0 while not done: x = x * 10 quotientList.append(x // d) r = x % d if r == 0: done = True elif remainderList[r] != -1: isRecurringDecimal = True cycleLength = counter - remainderList[r] done = True else: remainderList[r] = counter x = r counter += 1 if not isRecurringDecimal: print(1) # print("循環しません。小数点以下の商は", quotientList, "です。") else: print(cycleLength) print() # beforeRecurringCycle = quotientList[0:len(quotientList) - cycleLength] # recurringCycle = quotientList[len(quotientList) - cycleLength:] # print("循環します。") # if beforeRecurringCycle: # print("循環節に含まれない部分は", beforeRecurringCycle, "です。") # else: # print("循環節に含まれない部分はありません。") # print("循環節は", recurringCycle, "です。")