結果
| 問題 |
No.147 試験監督(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-09-08 08:47:09 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 207 ms / 2,000 ms |
| コード長 | 1,572 bytes |
| コンパイル時間 | 472 ms |
| コンパイル使用メモリ | 59,864 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-19 04:56:50 |
| 合計ジャッジ時間 | 1,910 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:50:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
50 | int n; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
using i64 = long long;
using mat = i64[2][2];
class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};
const int mod = int(1e9) + 7;
void matmul(mat a, mat b, mat res) {
mat r0 = {{0, 0}, {0, 0}};
r0[0][0] = (a[0][0]*b[0][0] + a[0][1]*b[1][0]) % mod;
r0[0][1] = (a[0][0]*b[0][1] + a[0][1]*b[1][1]) % mod;
r0[1][0] = (a[1][0]*b[0][0] + a[1][1]*b[1][0]) % mod;
r0[1][1] = (a[1][0]*b[0][1] + a[1][1]*b[1][1]) % mod;
memcpy(res, r0, sizeof(r0));
}
void matpow(mat a, i64 n, mat res) {
mat r1 = {{1, 0}, {0, 1}};
for(; n>0; n>>=1) {
if(n & 1) { matmul(r1, a, r1); }
matmul(a, a, a);
}
memcpy(res, r1, sizeof(r1));
}
i64 mod_pow(i64 a, i64 n, i64 mod) {
i64 res = 1LL;
for(i64 p=a; n>0; n>>=1) {
if(n & 1) { (res *= p) %= mod; }
(p *= p) %= mod;
}
return res;
}
i64 to_modint(string s, i64 mod) {
i64 res = 0;
for(char c : s) {
(res *= 10) += (c - '0');
res %= mod;
}
return res ? res : mod-1;
}
int main(void) {
int n; scanf("%d", &n);
i64 res = 1;
for(int i : range(n)) {
i64 c; string d; cin >> c >> d;
mat ma = {{1, 1}, {1, 0}};
mat powered;
matpow(ma, c+1, powered);
i64 y = to_modint(d, mod-1),
z = mod_pow(powered[0][0], y, mod);
(res *= z) %= mod;
}
printf("%d\n", int(res));
return 0;
}