結果

問題 No.181 A↑↑N mod M
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-06 00:19:17
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 617 bytes
コンパイル時間 1,285 ms
コンパイル使用メモリ 152,692 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 04:54:38
合計ジャッジ時間 2,392 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int dfs(int A, int N, int M, int minus){
	if (M <= 1) return 0;
	if (N == 0)
	{
		return 1;
	}
	vector<int> v;
	if (A % M == 0) return 0;
	long long temp = 1;
	map<int, int> m;
	do{
		m[temp] = v.size() + 1;
		v.push_back((int)temp);
		temp *= A;
		temp %= M;
		if (temp == 0) return 0;
	} while (m[temp] == 0);
	int loop = v.size() - (m[temp] - 1);
	int nextminus = (int)v.size() - loop;

	int r = dfs(A, N - 1, v.size(), nextminus);
	if (r < nextminus) r += loop;
	return v[r];
}

int main() {
	int A, N, M;
	cin >> A >> N >> M;
	
	cout << dfs(A, N, M, 0) << endl;
}

0