結果

問題 No.181 A↑↑N mod M
ユーザー t98slidert98slider
提出日時 2022-07-20 22:48:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 636 bytes
コンパイル時間 1,566 ms
コンパイル使用メモリ 169,032 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-15 10:18:25
合計ジャッジ時間 3,096 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 WA -
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 1 ms
4,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    int A, N, M;
    cin >> A >> N >> M;
    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 < tb[val])return order[EXP];
        return order[(EXP - tb[val]) % (tim - tb[val]) + tb[val]];
    };
    cout << rec(A, N, M) << endl;
}
0