結果

問題 No.3022 一元一次式 mod 1000000000
コンテスト
ユーザー nikoro256
提出日時 2025-02-15 02:42:53
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 308 ms / 2,000 ms
コード長 450 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 193 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 81,664 KB
最終ジャッジ日時 2026-07-02 19:49:07
合計ジャッジ時間 2,446 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import math
T=int(input())

for _ in range(T):
    N,M=map(int, input().split())
    p=10**9
    g = math.gcd(N,M,10**9)
    N%=p
    M%=p
    if N==0 and M==0:
        print(1)
        continue
    elif N==0:
        print(-1)
        continue
    N//=g
    M//=g
    t=10**9//g
    if N%t==0 or math.gcd(N,t)>1:
        print(-1)
    else:
        a = -M*pow(N,-1,t)%t
        if a==0:
            print(10**9)
            continue
        print(a)
0