結果

問題 No.3133 法B逆元
ユーザー hirakuuuu
提出日時 2025-05-02 21:33:07
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,128 bytes
コンパイル時間 6,379 ms
コンパイル使用メモリ 458,876 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-02 21:33:16
合計ジャッジ時間 7,769 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include <atcoder/all>

// 多倍長整数
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;

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;}

int main(){
    cpp_int n, b; cin >> n >> b;
    if(b == 1){
        cout << 0 << endl;
        return 0;
    }
    if(n == 0){
        cout << "NaN" << endl;
        return 0;
    }


    vector<int> seen((int)b, -1);
    cpp_int tmp = 0, i = 0;
    ll tmp_id = (ll)tmp;
    while(seen[tmp_id] == -1){
        seen[tmp_id] = (int)i;
        i++;
        tmp = (tmp+n)%b;
        tmp_id = (ll)tmp;
    }
    if(seen[1] == -1) cout << "NaN" << endl;
    else cout << seen[1] << endl;
    return 0;
}
0