結果
問題 | No.3022 一元一次式 mod 1000000000 |
ユーザー |
|
提出日時 | 2025-02-14 21:52:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 77 ms / 2,000 ms |
コード長 | 951 bytes |
コンパイル時間 | 2,296 ms |
コンパイル使用メモリ | 196,932 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-02-17 12:56:28 |
合計ジャッジ時間 | 3,203 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#include<bits/stdc++.h>#include<atcoder/math>using namespace std;using ll=long long;#define all(v) v.begin(),v.end()#define rall(v) v.rbegin(),v.rend()template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}int main(){ios::sync_with_stdio(false);cin.tie(nullptr);int T;cin>>T;while(T--){ll MOD=1'000'000'000;ll N,M;cin>>N>>M;N%=MOD;M%=MOD;if(N==0){if(M==0)cout<<1<<"\n";else cout<<-1<<"\n";continue;}ll g=gcd(N,MOD);if(M%g!=0)cout<<-1<<"\n";else{N/=g;M/=g;MOD/=g;ll inv=atcoder::inv_mod(N,MOD);ll ans=(inv*(MOD-M))%MOD;if(ans==0)ans+=MOD;cout<<ans<<"\n";}}}