結果

問題 No.251 大きな桁の復習問題(1)
ユーザー kazumakazuma
提出日時 2018-12-19 23:18:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 1,870 bytes
コンパイル時間 2,100 ms
コンパイル使用メモリ 202,816 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-26 00:14:47
合計ジャッジ時間 3,256 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 11 ms
4,348 KB
testcase_10 AC 11 ms
4,348 KB
testcase_11 AC 11 ms
4,348 KB
testcase_12 AC 11 ms
4,348 KB
testcase_13 AC 10 ms
4,348 KB
testcase_14 AC 11 ms
4,348 KB
testcase_15 AC 11 ms
4,348 KB
testcase_16 AC 11 ms
4,348 KB
testcase_17 AC 11 ms
4,348 KB
testcase_18 AC 11 ms
4,348 KB
testcase_19 AC 11 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0