結果
| 問題 |
No.3022 一元一次式 mod 1000000000
|
| コンテスト | |
| ユーザー |
nikoro256
|
| 提出日時 | 2025-02-15 02:42:53 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 449 ms / 2,000 ms |
| コード長 | 450 bytes |
| コンパイル時間 | 201 ms |
| コンパイル使用メモリ | 82,004 KB |
| 実行使用メモリ | 77,464 KB |
| 最終ジャッジ日時 | 2025-02-17 12:58:24 |
| 合計ジャッジ時間 | 2,632 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
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)
nikoro256