結果
問題 | No.3022 一元一次式 mod 1000000000 |
ユーザー |
|
提出日時 | 2025-02-14 22:15:10 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,209 bytes |
コンパイル時間 | 4,013 ms |
コンパイル使用メモリ | 274,232 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-02-14 22:16:39 |
合計ジャッジ時間 | 5,087 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 8 WA * 12 |
ソースコード
#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;ll g = gcd(n, MOD);if(m%g != 0){cout << -1 << endl;continue;}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;}