結果
| 問題 |
No.251 大きな桁の復習問題(1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-11-08 19:52:35 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 688 bytes |
| コンパイル時間 | 529 ms |
| コンパイル使用メモリ | 61,360 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-13 14:10:56 |
| 合計ジャッジ時間 | 6,384 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 WA * 2 |
ソースコード
#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;
}
// 今、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;
}