結果

問題 No.891 隣接3項間の漸化式
ユーザー tkmst201tkmst201
提出日時 2019-09-20 21:41:06
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,553 bytes
コンパイル時間 2,157 ms
コンパイル使用メモリ 151,956 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-12 18:30:09
合計ジャッジ時間 3,412 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

typedef vector<ll> vl;
typedef vector<vl> vvl;

vvl multi(vvl &a, vvl &b, ll mod) {
	vvl res(a.size(), vl(b[0].size()));
	
	REP(i, a.size()) {
		REP(j, b[0].size()) {
			REP(k, b.size()) {
				res[i][j] += a[i][k] * b[k][j] % mod;
				res[i][j] %= mod;
			}
		}
	}
	
	return res;
}

vvl pow(vvl x, ll n, ll mod) {
	vvl res(x.size(), vl(x.size()));
	
	REP(i, x.size()) res[i][i] = 1;
	
	while (n > 0) {
		if (n & 1) res = multi(res, x, mod);
		x = multi(x, x, mod);
		n >>= 1;
	}
	
	return res;
}

vvl init(ll a, ll b) {
	vvl res(2, vl(2));
	res[0][0] = a;
	res[0][1] = b;
	res[1][0] = 1;
	res[1][1] = 0;
	return res;
}

ll solve(ll x, ll mod, ll a, ll b) {
	vvl cur = init(a, b);
	
	vvl se(2, vl(1));
	se[0][0] = 1;
	se[1][0] = 0;
	
	cur = pow(cur, x - 1, mod);
	cur = multi(cur, se, mod);
	
	return cur[0][0];
}

int main() {
	ll a, b, n;
	cin >> a >> b >> n;
	
	cout << solve(n, MOD, a, b) << endl;
	return 0;
}
0