結果

問題 No.3022 一元一次式 mod 1000000000
ユーザー tokitsukaze
提出日時 2025-02-14 21:51:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 898 bytes
コンパイル時間 1,388 ms
コンパイル使用メモリ 160,516 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-02-14 21:53:27
合計ジャッジ時間 2,417 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9 WA * 11
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:53:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   53 |         scanf("%d",&T);
      |         ~~~~~^~~~~~~~~
main.cpp:56:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   56 |                 scanf("%lld%lld",&a,&b);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int MAX=5e5+10;
const int mod=1e9;
ll exgcd(ll a,ll b,ll &x,ll &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
ll g,tmp;
g=exgcd(b,a%b,x,y);
tmp=x;
x=y;
y=tmp-a/b*y;
return g;
}
ll linear_equation(ll a,ll b,ll c,ll &x,ll &y)
{
ll g,dx,dy,t;
g=exgcd(a,b,x,y);
if(a==0&&b==0)
{
if(c) return -1;
x=y=0;
return g;
}
if(c%g) return -1; //no solution
dx=b/g,dy=-a/g;
x*=c/g,y*=c/g;
if(dx==0) t=(y-y%dy)/dy;
else t=(x%dx-x)/dx;
if(x+dx*t<=0) t++;
x+=dx*t,y+=dy*t;
return g;
}
/*
xa+yb=c
get x,y and x>0 is min
have solution: c%gcd(a,b)==0
x=x0+dx*t
y=y0-dy*t
*/
int main()
{
int T;
ll x,y,a,b;
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld",&a,&b);
a%=mod;
b%=mod;
x=y=0;
if(linear_equation(a,0,mod-b,x,y)==-1) puts("-1");
else printf("%lld\n",x);
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0