結果

問題 No.147 試験監督(2)
ユーザー __math__math
提出日時 2015-02-28 01:26:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 393 ms / 2,000 ms
コード長 2,142 bytes
コンパイル時間 862 ms
コンパイル使用メモリ 100,896 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 03:54:02
合計ジャッジ時間 3,256 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <iterator>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

const int MOD = ten(9) + 7;
typedef vector<ll> Row;
typedef vector<Row> Mat;
Mat mul(const Mat& a, const Mat& b)
{
	int n = a.size();
	int m = a[0].size();
	int x = b.size();
	int y = b[0].size();
	assert(m == x);

	Mat c(n, Row(y));
	for (int i = 0; i < n; ++i)
		for (int k = 0; k < m; ++k)
			for (int j = 0; j < y; ++j)
				(c[i][j] += a[i][k] * b[k][j]) %= MOD;
	return c;
}

Mat pow(const Mat& _a, ll e)
{
	Mat a = _a;
	int n = a.size();
	Mat res(n, Row(n));
	for (int i = 0; i < n; ++i)
		res[i][i] = 1;

	while (e > 0) {
		if (e & 1)
			res = mul(res, a);
		a = mul(a, a);
		e /= 2;
	}

	return res;
}

template<class T> ll mod_pow(T a, T n, T mod){
	ll ret = 1;
	ll p = a % mod;
	while (n) {
		if (n & 1) ret = ret * p % mod;
		p = p * p % mod;
		n >>= 1;
	}
	return ret;
}

ll fib(ll n){
	// 0,1,1,2,3,5,8 ...;
	if (n == 0) return 0;
	Mat b = Mat(2,Row(2));
	b[0][0] = b[0][1] = b[1][0] = 1;
	return pow(b, n - 1)[0][0];
}

int main(){
	int n; cin >> n;
	ll ans = 1;
	while (n--) {
		ll c; char s[1000];
		scanf("%lld%s", &c, &s);
		ll d = 0;
		for (int i = 0; s[i]; i++) {
			d = d * 10 + s[i] - '0';
			if (d > MOD - 1) d %= MOD - 1;
		}
		ll cur = fib(c + 2);
		ans = ans * mod_pow<ll>(cur, d, MOD) % MOD;
	}
	cout << ans % MOD << endl;
}
0