結果

問題 No.1842 Decimal Point
ユーザー tamatotamato
提出日時 2022-02-18 22:39:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,010 bytes
コンパイル時間 440 ms
コンパイル使用メモリ 87,688 KB
実行使用メモリ 80,868 KB
最終ジャッジ日時 2023-09-11 19:40:16
合計ジャッジ時間 2,679 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,708 KB
testcase_01 AC 225 ms
80,060 KB
testcase_02 AC 485 ms
80,868 KB
testcase_03 WA -
testcase_04 AC 348 ms
80,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    import math
    input = sys.stdin.readline

    inv = {1: 1, 3: 7, 7: 3, 9: 9}
    for _ in range(int(input())):
        a, b, c = map(int, input().split())
        q = pow(10, c, b)
        cnt2 = cnt5 = 0
        while b % 2 == 0:
            cnt2 += 1
            b //= 2
            q //= 2
        while b % 5 == 0:
            cnt5 += 1
            b //= 5
            q //= 5
        cnt = max(cnt2, cnt5)
        if cnt > c:
            if cnt2 < cnt5:
                a *= 2 ** (cnt5 - cnt2)
            else:
                a *= 5 ** (cnt2 - cnt5)
            d = cnt - c
            x = math.floor(a / b)
            x = str(x).zfill(100)
            print(x[-d - 1])
            continue
        r = (pow(2, c - cnt2, 10) * pow(5, c - cnt5, 10)) % 10
        p = ((r-q) * inv[b % 10]) % 10
        ans0 = (a * p) % 10
        ans1 = math.floor(a * q / b) % 10
        print((ans0 + ans1) % 10)


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