結果

問題 No.181 A↑↑N mod M
ユーザー t98slidert98slider
提出日時 2022-07-21 00:27:49
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 632 bytes
コンパイル時間 1,646 ms
コンパイル使用メモリ 170,324 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-02 14:12:47
合計ジャッジ時間 2,861 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 14 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    function<int(int, int, int)> rec = [&](int V, int N, int MOD){
        if(N == 0)return 1;
        if(MOD == 1)return 0;
        vector<int> order, tb(MOD, -1);
        int val = 1, tim = 0;
        while(tb[val] == -1){
            tb[val] = tim++;
            order.push_back(val);
            (val *= V % MOD )%= MOD;
        }
        int EXP = rec(V, N - 1, tim - tb[val]);
        if(EXP < tim)return order[EXP];
        return order[(EXP - tb[val]) % (tim - tb[val]) + tb[val]];
    };
    int A, N, M;
    cin >> A >> N >> M;
    cout << rec(A, N, M) << endl;
}
0