結果

問題 No.3022 一元一次式 mod 1000000000
ユーザー Today03
提出日時 2025-02-15 05:41:18
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 281 ms / 2,000 ms
コード長 741 bytes
コンパイル時間 3,257 ms
コンパイル使用メモリ 280,328 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-02-17 12:58:44
合計ジャッジ時間 4,122 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 10;
const ll INFL = 4e18;

#include <atcoder/math>

int main() {
    int T;
    cin >> T;

    while (T--) {
        ll N, M;
        cin >> N >> M;

        ll mod = 1e9;
        N %= mod, M %= mod, M = (mod - M) % mod;

        if (M == N) {
            cout << 1 << '\n';
        } else if (N == 0) {
            cout << -1 << '\n';
        } else if (M == 0) {
            cout << mod << '\n';
        } else {
            auto [res, lcm] = atcoder::crt({0, M}, {N, mod});

            if (lcm == 0 || res % N != 0) {
                cout << -1 << '\n';
            } else {
                cout << res / N << '\n';
            }
        }
    }
}
0