結果

問題 No.1339 循環小数
ユーザー Yuta IidaYuta Iida
提出日時 2023-11-19 21:21:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,486 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 117,488 KB
最終ジャッジ日時 2023-11-19 21:21:28
合計ジャッジ時間 4,425 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
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 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 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, "です。")
0