結果
問題 | No.1275 綺麗な式 |
ユーザー |
![]() |
提出日時 | 2020-10-31 09:55:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 751 bytes |
コンパイル時間 | 1,934 ms |
コンパイル使用メモリ | 193,780 KB |
最終ジャッジ日時 | 2025-01-15 18:26:20 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 60 |
ソースコード
#include <bits/stdc++.h> using namespace std; constexpr int64_t mod = 1000000007; class PairInt { public: int64_t x, y, z; PairInt(int64_t a, int64_t b, int64_t c) { x = a; y = b; z = c; } PairInt mul(PairInt a, PairInt b) { return PairInt{(a.x*b.x%mod + a.y*b.y%mod*a.z) % mod, (a.y*b.x%mod + a.x*b.y) % mod, a.z}; } PairInt power(int64_t n) { PairInt res(1, 0, this->z); while (n) { if (n % 2) res = mul(res, *this); *this = mul(*this, *this); n /= 2; } return res; } }; int main() { int64_t a, b, n; cin >> a >> b >> n; PairInt z(a, 1, b); cout << z.power(n).x * 2 % mod << endl; }