結果

問題 No.3022 一元一次式 mod 1000000000
ユーザー ArcAki
提出日時 2025-02-15 09:29:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 488 ms / 2,000 ms
コード長 811 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 82,280 KB
実行使用メモリ 79,240 KB
最終ジャッジ日時 2025-02-17 12:58:32
合計ジャッジ時間 3,232 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    t = int(input())
    for _ in range(t):
        n, m = map(int, input().split())
        cntn1 = cntn2 = cntm1 = cntm2 = 0
        x = n
        while x%2==0:
            x //= 2
            cntn1 += 1
        while x%5==0:
            x //= 5
            cntn2 += 1
        x = m
        while x%2==0:
            cntm1 += 1
            x //= 2
        while x%5==0:
            x //= 5
            cntm2 += 1
        if min(cntn1, 9) > cntm1 or min(cntn2, 9) > cntm2:
            print("-1")
            continue
        div = (1<<min(cntn1, 9))*pow(5, min(cntn2, 9))
        x = n//div
        y = m//div
        modulo = 1000000000//div
        inv = pow(x, -1, modulo)
        res = (modulo-y*inv%modulo)%modulo
        print(res if res else modulo)


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