結果

問題 No.251 大きな桁の復習問題(1)
ユーザー masamasa
提出日時 2015-11-08 20:52:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 619 ms / 5,000 ms
コード長 760 bytes
コンパイル時間 480 ms
コンパイル使用メモリ 61,780 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 17:08:01
合計ジャッジ時間 6,144 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 356 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 586 ms
4,376 KB
testcase_10 AC 377 ms
4,376 KB
testcase_11 AC 44 ms
4,380 KB
testcase_12 AC 226 ms
4,380 KB
testcase_13 AC 535 ms
4,376 KB
testcase_14 AC 56 ms
4,376 KB
testcase_15 AC 270 ms
4,376 KB
testcase_16 AC 167 ms
4,376 KB
testcase_17 AC 619 ms
4,380 KB
testcase_18 AC 579 ms
4,380 KB
testcase_19 AC 404 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 333 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

const long long P = 129402307;

int main() {
	string nstr, mstr;
	long long n, m;

	cin >> nstr >> mstr;

	n = 0;
	for (int i = 0; i < nstr.size(); i++) {
		n = (n * 10 + nstr[i] - '0') % P;
	}
	if (n == 0) {
		cout << (mstr == "0" ? 1 : 0) << endl;
		return 0;
	}

	// 今、n = n % pだから n < p
	// またpが素数
	// なので n, pは互いに素
	// フェルマーの小定理
	// a^(p-1) ≡ 1 (mod p)

	m = 0;
	for (int i = 0; i < mstr.size(); i++) {
		m = (m * 10 + mstr[i] - '0') % (P - 1);
	}

	long long ans = 1;
	for (int i = 0; i < m; i++) {
		ans = (ans * n) % P;
	}

	cout << ans << endl;
	return 0;
}
0