結果
| 問題 | 
                            No.3022 一元一次式 mod 1000000000
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2025-02-14 22:02:48 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 588 bytes | 
| コンパイル時間 | 1,574 ms | 
| コンパイル使用メモリ | 160,684 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2025-02-14 22:08:02 | 
| 合計ジャッジ時間 | 2,595 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge6 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 8 WA * 12 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |         scanf("%d",&T);
      |         ~~~~~^~~~~~~~~
main.cpp:35:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |                 scanf("%lld%lld",&a,&b);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~
            
            ソースコード
#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 inv_exgcd(ll a,ll p)
{
	ll 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 printf("%lld\n",res*(mod-b)%mod);
	}
	return 0;
}