結果
| 問題 |
No.891 隣接3項間の漸化式
|
| コンテスト | |
| ユーザー |
hamburg_soshun
|
| 提出日時 | 2019-09-24 16:05:32 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 965 bytes |
| コンパイル時間 | 619 ms |
| コンパイル使用メモリ | 79,444 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-19 05:08:20 |
| 合計ジャッジ時間 | 1,882 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 39 |
ソースコード
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <map>
#include <queue>
#include <bitset>
using namespace std;
long long mod = 1000000007;
int main() {
long long a, b, n; cin >> a >> b >> n;
if (n <= 1) {
cout << n << endl;
return 0;
}
long long x1 = 1, x2 = 0, x3 = 0, x4 = 1;
long long y1, y2, y3, y4;
long long a1 = a, a2 = b, a3 = 1, a4 = 0;
while (n > 0) {
if (n % 2 == 1) {
y1 = (a1 * x1 + a2 * x3) % mod; y2 = (a1 * x2 + a2 * x4) % mod;
y3 = (a3 * x1 + a4 * x3) % mod; y4 = (a3 * x2 + a4 * x4) % mod;
x1 = y1; x2 = y2; x3 = y3; x4 = y4;
}
{
y1 = (a1 * a1 + a2 * a3) % mod; y2 = (a1 * a2 + a2 * a4) % mod;
y3 = (a3 * a1 + a4 * a3) % mod; y4 = (a3 * a2 + a4 * a4) % mod;
a1 = y1; a2 = y2; a3 = y3; a4 = y4;
}
n /= 2;
}
cout << x3 << endl;
return 0;
}
hamburg_soshun