結果

問題 No.25 有限小数
ユーザー mkawa2mkawa2
提出日時 2020-01-06 11:34:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 563 ms / 5,000 ms
コード長 754 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 44,224 KB
最終ジャッジ日時 2024-05-02 10:46:47
合計ジャッジ時間 18,860 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 536 ms
43,616 KB
testcase_01 AC 533 ms
43,972 KB
testcase_02 AC 540 ms
43,956 KB
testcase_03 AC 539 ms
43,964 KB
testcase_04 AC 563 ms
43,708 KB
testcase_05 AC 537 ms
43,736 KB
testcase_06 AC 537 ms
43,608 KB
testcase_07 AC 534 ms
43,700 KB
testcase_08 AC 537 ms
43,708 KB
testcase_09 AC 539 ms
43,716 KB
testcase_10 AC 533 ms
43,452 KB
testcase_11 AC 536 ms
43,476 KB
testcase_12 AC 528 ms
43,844 KB
testcase_13 AC 536 ms
43,964 KB
testcase_14 AC 536 ms
43,612 KB
testcase_15 AC 538 ms
43,708 KB
testcase_16 AC 544 ms
43,452 KB
testcase_17 AC 538 ms
43,452 KB
testcase_18 AC 530 ms
43,968 KB
testcase_19 AC 538 ms
43,964 KB
testcase_20 AC 540 ms
44,224 KB
testcase_21 AC 528 ms
43,708 KB
testcase_22 AC 538 ms
44,100 KB
testcase_23 AC 535 ms
43,840 KB
testcase_24 AC 538 ms
43,600 KB
testcase_25 AC 532 ms
43,836 KB
testcase_26 AC 529 ms
43,992 KB
testcase_27 AC 532 ms
44,000 KB
testcase_28 AC 527 ms
43,836 KB
testcase_29 AC 540 ms
43,960 KB
testcase_30 AC 542 ms
43,708 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