結果

問題 No.147 試験監督(2)
ユーザー pekempeypekempey
提出日時 2015-08-21 12:44:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 1,435 bytes
コンパイル時間 1,147 ms
コンパイル使用メモリ 146,196 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 14:19:09
合計ジャッジ時間 2,754 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 200 ms
4,380 KB
testcase_01 AC 200 ms
4,380 KB
testcase_02 AC 201 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) rep2 (i, 0, a)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) repr2 (i, 0, a)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define asn(a, b, c) fill_n(&(b), sizeof(a) / sizeof(b), c)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;

void matmul(ll A[2][2], ll B[2][2]) {
	ll a[2][2], b[2][2];
	rep (i, 2) {
		rep (j, 2) {
			a[i][j] = A[i][j];
			b[i][j] = B[i][j];
			B[i][j] = 0;
		}
	}
	rep (i, 2) {
		rep (k, 2) {
			rep (j, 2) {
				(B[i][j] += a[i][k] * b[k][j]) %= mod;
			}
		}
	}
}

void matpow(ll A[2][2], ll b, ll res[2][2]) {
	rep (i, 2) rep (j, 2) res[i][j] = i == j;
	while (b) {
		if (b & 1) matmul(A, res);
		matmul(A, A);
		b >>= 1;
	}
}

ll modpow(ll a, ll b) {
	ll res = 1;
	while (b > 0) {
		if (b & 1) (res *= a) %= mod;
		(a *= a) %= mod;
		b >>= 1;
	}
	return res;
}

ll bigmodulo(string &s, ll m) {
	ll res = 0;
	for (char d : s) {
		res *= 10;
		res += d - '0';
		res %= m;		
	}
	return res;
}

ll bigmodpow(ll a, string &b) {
	if (a == 0) return 0;
	ll B = bigmodulo(b, mod - 1);
	return modpow(a, B);	
}

int main() {
	int N;
	cin >> N;
	ll ans = 1;
	rep (i, N) {
		ll C;
		string D;
		cin >> C >> D;

		ll A[2][2] = {{1, 1}, {1, 0}};
		ll An[2][2];
		matpow(A, C, An);
		ll m = (An[0][0] + An[1][0]) % mod;
		ans *= bigmodpow(m, D);
		ans %= mod;
	}
	cout << ans << endl;

	return 0;
}
0