結果

問題 No.3133 法B逆元
ユーザー rgnerdplayer
提出日時 2025-05-03 03:48:06
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,157 bytes
コンパイル時間 3,608 ms
コンパイル使用メモリ 277,220 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2025-05-03 03:48:11
合計ジャッジ時間 4,534 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

using i128 = __int128_t;
istream& operator>>(istream &is, i128 &n) {
    string s;
    cin >> s;
    bool neg = false;
    if (s[0] == '-') {
        neg = true;
        s = s.substr(1);
    }
    n = 0;
    for (auto ch : s) {
        n = n * 10 + ch - '0';
    }
    if (neg) {
        n = -n;
    }
    return is;
}
ostream& operator<<(ostream &os, i128 n) {
    if (n < 0) {
        os << '-';
        n = -n;
    }
    if (n == 0) {
        os << 0;
    } else {
        string s;
        while (n > 0) {
            s += '0' + n % 10;
            n /= 10;
        }
        reverse(s.begin(), s.end());
        os << s;
    }
    return os;
}

i128 gcd(i128 x, i128 y) {
    return y == 0 ? x : gcd(y, x % y);
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    auto solve = [&]() {
        i128 n, b;
        cin >> n >> b;

        for (int i = 0; i < b; i++) {
            if ((n * i) % b == 1 % b) {
                cout << i << '\n';
                return;
            }
        }

        cout << "NaN" << '\n';
    };
    
    solve();
    
    return 0;
}
0