結果
| 問題 |
No.251 大きな桁の復習問題(1)
|
| コンテスト | |
| ユーザー |
kazuma
|
| 提出日時 | 2018-12-19 23:18:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 15 ms / 5,000 ms |
| コード長 | 1,870 bytes |
| コンパイル時間 | 2,310 ms |
| コンパイル使用メモリ | 195,032 KB |
| 最終ジャッジ日時 | 2025-01-06 19:41:06 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template<int MOD>
class mod_int {
unsigned x;
public:
mod_int() : x(0) { }
mod_int(int sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
mod_int(long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
int get() const { return (int)x; }
mod_int &operator+=(mod_int that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
mod_int &operator-=(mod_int that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
mod_int &operator*=(mod_int that) { x = (unsigned long long)x * that.x % MOD; return *this; }
mod_int &operator/=(mod_int that) { return *this *= that.inverse(); }
mod_int operator+(mod_int that) const { return mod_int(*this) += that; }
mod_int operator-(mod_int that) const { return mod_int(*this) -= that; }
mod_int operator*(mod_int that) const { return mod_int(*this) *= that; }
mod_int operator/(mod_int that) const { return mod_int(*this) /= that; }
bool operator==(const mod_int& that) const { return x == that.x; }
mod_int inverse() const {
long long a = x, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
return mod_int(u);
}
};
template<int MOD>
istream& operator >> (istream& is, mod_int<MOD>& val) {
long long x;
is >> x; val = x;
return is;
}
template<int MOD>
ostream& operator << (ostream& os, const mod_int<MOD>& val) {
os << val.get();
return os;
}
const int mod = 129402307;
using mint = mod_int<mod>;
int main()
{
string N, M;
cin >> N >> M;
mint n = 0;
for (auto c : N) {
n *= 10;
n += c - '0';
}
reverse(M.begin(), M.end());
mint res = 1;
for (auto c : M) {
for (int i = 0; i < c - '0'; i++) {
res *= n;
}
mint tmp = 1;
for (int i = 0; i < 10; i++) {
tmp *= n;
}
n = tmp;
}
cout << res << endl;
return 0;
}
kazuma