結果
問題 |
No.147 試験監督(2)
|
ユーザー |
|
提出日時 | 2016-10-30 17:03:47 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 87 ms / 2,000 ms |
コード長 | 1,282 bytes |
コンパイル時間 | 1,396 ms |
コンパイル使用メモリ | 160,700 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-24 23:41:44 |
合計ジャッジ時間 | 3,161 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:61:19: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 2 has type ‘int64_t*’ {aka ‘long int*’} [-Wformat=] 61 | scanf("%lld %s", &C, D); | ~~~^ ~~ | | | | | int64_t* {aka long int*} | long long int* | %ld main.cpp:61:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 61 | scanf("%lld %s", &C, D); | ~~~~~^~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; typedef array<int, 2> F; const int mod = 1e9 + 7; 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(F a, F b) { F res; res[0] = add(mul(a[0], b[0]), mul(a[1], b[1])); res[1] = add(mul(a[0], b[1]), mul(a[1], b[0]), mul(a[1], b[1])); return res; } F fib(int64_t n) { F f = { 1, 0 }; F g = { 0, 1 }; while (n > 0) { if (n & 1) f = mul(f, g); g = mul(g, g); n >>= 1; } return f; } int main() { int n; cin >> n; int ans = 1; while (n--) { int64_t C; static char D[210]; scanf("%lld %s", &C, D); int64_t d = 0; for (int i = 0; D[i] != 0; i++) { d = (d * 10 + D[i] - '0') % (mod - 1); } F f = fib(C); ans = mul(ans, pow(add(f[0], f[1], f[1]), d)); } cout << ans << endl; }