結果

問題 No.891 隣接3項間の漸化式
ユーザー hamburg_soshunhamburg_soshun
提出日時 2019-09-24 16:05:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 965 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 79,340 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 08:54:46
合計ジャッジ時間 1,899 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 1 ms
4,348 KB
testcase_36 AC 1 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 1 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0