結果
| 問題 |
No.147 試験監督(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-30 18:00:38 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 50 ms / 2,000 ms |
| コード長 | 1,909 bytes |
| コンパイル時間 | 1,326 ms |
| コンパイル使用メモリ | 162,136 KB |
| 実行使用メモリ | 6,816 KB |
| 最終ジャッジ日時 | 2024-11-24 23:48:43 |
| 合計ジャッジ時間 | 2,160 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
// #define getchar getchar_unlocked
// #define putchar putchar_unlocked
typedef array<int, 2> F;
const int mod = 1e9 + 7;
const int B = 6;
F dub[60 / B][1 << B];
int mul(int x, int y) {
return int64_t(x) * y % mod;
}
int add(int x, int y) {
return (x += y) >= mod ? x - mod : x;
}
template<class... T>
int add(int x, T... y) {
return add(x, add(y...));
}
void upd(int &x, int y) {
x = add(x, y);
}
int pow(int a, int64_t b) {
if (a == 0) return 0;
int res = 1;
while (b > 0) {
if (b & 1) res = mul(res, a);
a = mul(a, a);
b >>= 1;
}
return res;
}
F mul(const F &a, const F &b) {
F res;
res[0] = (int64_t(a[0]) * b[0] + int64_t(a[1]) * b[1]) % mod;
res[1] = (int64_t(a[0] + a[1]) * b[1] + int64_t(a[1]) * b[0]) % mod;
return res;
}
F fib(int64_t n) {
F f = { 1, 0 };
for (int i = 0; n > 0; i++) {
if (n % (1 << B) != 0) f = mul(f, dub[i][n % (1 << B)]);
n >>= B;
}
return f;
}
int64_t in_int64() {
char c;
while ((c = getchar()) < '0') if (c == EOF) return -1;
int64_t n = c - '0';
while ((c = getchar()) >= '0') n = n * 10 + (c - '0');
return n;
}
int64_t in_bigint() {
char c;
while ((c = getchar()) < '0') if (c == EOF) return -1;
int64_t n = c - '0';
while ((c = getchar()) >= '0') n = (n * 10 + c - '0') % (mod - 1);
return n;
}
int main() {
dub[0][1][1] = 1;
for (int i = 0; i < 60 / B; i++) {
if (i > 0) dub[i][1] = mul(dub[i - 1][(1 << B) - 1], dub[i - 1][1]);
for (int j = 2; j < 1 << B; j++) {
dub[i][j] = mul(dub[i][1], dub[i][j - 1]);
}
}
int n = in_int64();
int ans = 1;
for (int i = 0; i < n; i++) {
F f = fib(in_int64());
ans = mul(ans, pow(add(f[0], f[1], f[1]), in_bigint()));
}
cout << ans << endl;
}