結果

問題 No.891 隣接3項間の漸化式
ユーザー bal4ubal4u
提出日時 2019-09-20 22:42:10
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 936 bytes
コンパイル時間 941 ms
コンパイル使用メモリ 29,368 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-12 20:21:52
合計ジャッジ時間 2,357 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// yukicoder 891 隣接3項間の漸化式
// 2019.9.20 bal4u

#include <stdio.h>
#include <string.h>

typedef long long ll;

#define MOD 1000000007
#define SZ 2
#define MSZ (sizeof(com))
int com[SZ][SZ], a[SZ][SZ];

void mat_mul(int ab[SZ][SZ], int a[SZ][SZ], int b[SZ][SZ], int n) {
	int i, r, c;
	
	memset(ab, 0, MSZ);
	for (r = 0; r < n; r++) for (i = 0; i < n; i++) for (c = 0; c < n; c++)
		ab[r][c] = (ab[r][c] + (ll)a[r][i] * b[i][c]) % MOD;
}

void mat_pow(int ap[SZ][SZ], int a[SZ][SZ], int n, int p) {
	int i, tmp[SZ][SZ];
	
	memset(ap, 0, MSZ);
	for (i = 0; i < n; i++) ap[i][i] = 1;
	while (p > 0) {
		if (p & 1) mat_mul(tmp, ap, a, n), memcpy(ap, tmp, MSZ);
		mat_mul(tmp, a, a, n), memcpy(a, tmp, MSZ);
		p >>= 1;
	}
}

int main()
{
	int x, y, n;
	
	scanf("%d%d%d", &x, &y, &n);
	a[0][0] = x, a[0][1] = y;
	a[1][0] = 1, a[1][1] = 0;
	mat_pow(com, a, 2, n);  // 行列のべき乗
	printf("%d\n", com[1][0]);
	return 0;
}
0