結果

問題 No.25 有限小数
ユーザー szkhtsszkhts
提出日時 2021-05-26 09:05:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,176 bytes
コンパイル時間 125 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-04-23 06:02:07
合計ジャッジ時間 2,449 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
11,392 KB
testcase_01 AC 37 ms
11,520 KB
testcase_02 AC 35 ms
11,520 KB
testcase_03 AC 36 ms
11,648 KB
testcase_04 AC 36 ms
11,392 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 36 ms
11,520 KB
testcase_08 AC 38 ms
11,392 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 35 ms
11,520 KB
testcase_12 AC 38 ms
11,520 KB
testcase_13 WA -
testcase_14 AC 36 ms
11,392 KB
testcase_15 AC 35 ms
11,520 KB
testcase_16 AC 37 ms
11,648 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 36 ms
11,520 KB
testcase_20 AC 35 ms
11,392 KB
testcase_21 AC 36 ms
11,520 KB
testcase_22 AC 36 ms
11,520 KB
testcase_23 AC 37 ms
11,520 KB
testcase_24 AC 36 ms
11,520 KB
testcase_25 AC 37 ms
11,520 KB
testcase_26 AC 36 ms
11,392 KB
testcase_27 AC 36 ms
11,520 KB
testcase_28 AC 36 ms
11,520 KB
testcase_29 AC 35 ms
11,520 KB
testcase_30 AC 36 ms
11,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from fractions import Fraction

# 有限小数かどうか判定する関数
def isFinite(num,den):
    fra=Fraction(num,den)     # 既約分数にする
    den=fra.denominator       # 既約分数の分母を得る
    while den%2==0:           # 2で割れるところまで割る
        den//=2
    while den%5==0:           # 5で割れるところまで割る
        den//=5
    return den==1

def main():
    N = int(input())
    M = int(input())

    if N % M == 0:
        a = str(N / M)
        for i in range(len(a) - 1, -1, -1):
            if a[i] == '0' or a[i] == '.':
                continue
            else:
                print(a[i])
                break            
    else:
        if isFinite(N, M):
            a = str(N / M)
            if 'e' in a:
                b = a.find('e')
                print(a[b - 1])
            else:
                for i in range(len(a) - 1, -1, -1):
                    if a[i] == '0' or a[i] == '.':
                        continue
                    else:
                        print(a[i])
                        break            
        else:
            print(-1)

if __name__ == '__main__':
    main()
0