結果
| 問題 | No.3022 一元一次式 mod 1000000000 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-02-14 22:17:37 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 669 bytes |
| 記録 | |
| コンパイル時間 | 1,152 ms |
| コンパイル使用メモリ | 181,468 KB |
| 実行使用メモリ | 6,528 KB |
| 最終ジャッジ日時 | 2026-07-01 08:24:56 |
| 合計ジャッジ時間 | 2,186 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 WA * 12 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 i128;
const int INF=0x3f3f3f3f;
const int MAX=5e5+10;
const int mod=1e9;
i128 exgcd(i128 a,i128 b,i128 &x,i128 &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
i128 g,tmp;
g=exgcd(b,a%b,x,y);
tmp=x;
x=y;
y=tmp-a/b*y;
return g;
}
i128 inv_exgcd(ll a,ll p)
{
i128 g,x,y;
g=exgcd(a,p,x,y);
return g==1?(x%p+p)%p:-1;
}
int main()
{
int T;
ll a,b,res;
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld",&a,&b);
a%=mod;
b%=mod;
res=inv_exgcd(a,mod);
if(res==-1) puts("-1");
else
{
res=res*(mod-b)%mod;
if(res==0) res+=mod;
cout<<res<<"\n";
}
}
return 0;
}