結果

問題 No.25 有限小数
ユーザー mkawa2mkawa2
提出日時 2020-01-06 11:34:50
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 754 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 29,460 KB
最終ジャッジ日時 2023-08-14 22:36:52
合計ジャッジ時間 5,657 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
29,340 KB
testcase_01 AC 133 ms
29,272 KB
testcase_02 AC 134 ms
29,364 KB
testcase_03 AC 134 ms
29,264 KB
testcase_04 AC 135 ms
29,348 KB
testcase_05 AC 134 ms
29,256 KB
testcase_06 AC 134 ms
29,436 KB
testcase_07 AC 131 ms
29,328 KB
testcase_08 AC 133 ms
29,276 KB
testcase_09 AC 135 ms
29,368 KB
testcase_10 AC 133 ms
29,300 KB
testcase_11 AC 133 ms
29,300 KB
testcase_12 AC 135 ms
29,300 KB
testcase_13 AC 129 ms
29,300 KB
testcase_14 AC 131 ms
29,300 KB
testcase_15 AC 134 ms
29,252 KB
testcase_16 AC 131 ms
29,276 KB
testcase_17 AC 130 ms
29,304 KB
testcase_18 AC 132 ms
29,288 KB
testcase_19 AC 131 ms
29,460 KB
testcase_20 AC 132 ms
29,388 KB
testcase_21 AC 131 ms
29,344 KB
testcase_22 AC 131 ms
29,304 KB
testcase_23 AC 131 ms
29,320 KB
testcase_24 AC 133 ms
29,332 KB
testcase_25 AC 131 ms
29,256 KB
testcase_26 AC 131 ms
29,300 KB
testcase_27 AC 131 ms
29,304 KB
testcase_28 AC 133 ms
29,408 KB
testcase_29 AC 130 ms
29,340 KB
testcase_30 AC 132 ms
29,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
import numpy as np

def II(): return int(sys.stdin.readline())

def main():
    def lowest(a):
        while a%10==0:a//=10
        a%=10
        print(a)
        exit()

    def cnt_factor(m):
        c2=c5=0
        while m&1==0:
            m>>=1
            c2+=1
        while m%5==0:
            m//=5
            c5+=1
        if m==1:return c2,c5
        return -1,-1

    n=II()
    m=II()
    g=np.gcd(m,n)
    n,m=n//g,m//g
    if m==1:lowest(n)
    c2,c5=cnt_factor(m)
    if c2==-1:print(-1)
    elif c2==c5:lowest(n)
    elif c2>c5:print(5)
    else:
        #/5=*0.2なのでc5回2をかけたときの最下位の数が答え
        c5-=c2
        n%=5
        print(pow(2,c5,10)*n%10)

main()
0