結果
問題 | No.3022 一元一次式 mod 1000000000 |
ユーザー |
|
提出日時 | 2025-02-14 22:29:37 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,458 bytes |
コンパイル時間 | 5,737 ms |
コンパイル使用メモリ | 275,172 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-02-14 22:29:50 |
合計ジャッジ時間 | 4,855 ms |
ジャッジサーバーID (参考情報) |
judge7 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 WA * 3 |
ソースコード
#include <bits/stdc++.h>// #include <atcoder/all>using namespace std;// using namespace atcoder;#define rep(i, a, n) for(int i = a; i < n; i++)#define rrep(i, a, n) for(int i = a; i >= n; i--)#define inr(l, x, r) (l <= x && x < r)#define ll long long#define ld long double// using mint = modint1000000007;// using mint = modint998244353;constexpr int IINF = 1001001001;constexpr ll INF = 1e18;template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}ll gcd(ll a, ll b){if(a%b == 0) return b;else return gcd(b, a%b);}ll extGCD(ll a, ll b, ll &x, ll &y){if (b == 0) {x = 1;y = 0;return a;}ll d = extGCD(b, a%b, y, x);y -= a/b*x;return d;}int main(){int t; cin >> t;while(t--){ll MOD = 1e9;ll n, m; cin >> n >> m;n %= MOD, m %= MOD;if(n == 0){if(m == 0) cout << 1 << endl;else cout << 0 << endl;continue;}if(m == 0){cout << MOD << endl;continue;}ll g = gcd(n, MOD);if(m%g != 0){cout << -1 << endl;continue;}n /= g, m /= g, MOD /= g;ll x, y;g = extGCD(n, MOD, x, y);x %= MOD;if(x < 0) x += MOD;ll ans = ((MOD-m)*x)%MOD;cout << ans << endl;}return 0;}