結果

問題 No.3036 Restricted Lucas (Easy)
ユーザー kurenai3110kurenai3110
提出日時 2018-04-02 01:09:53
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,902 bytes
コンパイル時間 1,623 ms
コンパイル使用メモリ 66,648 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 13:14:08
合計ジャッジ時間 3,187 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;

const int zero = false;
const int one = true;
const int two = one + true;
const int three = two + true;
const int four = three + true;
const int five = four + true;
const int six = five + true;
const int seven = six + true;
const int eight = seven + true;
const int nine = eight + true;
const int ten = nine + true;

ll product(ll a, ll b) {
	if (b == zero)return zero;
	ll cnt = one;
	ll ret = a;
	while (b >= cnt + cnt) {
		ret += ret;
		cnt += cnt;
	}

	return ret + product(a, b - cnt);
}

ll mod(ll a, ll b) {
	while (a >= b) {
		ll m = b;
		while (a >= m + m)m += m;
		a -= m;
	}
	return a;
}

vector<vector<ll>> mul(vector<vector<ll>>&a, vector<vector<ll>>&b, ll p) {
	vector<vector<ll>>c(a.size(), vector<ll>(b.size()));
	
	for (ll i = zero; i<a.size(); i++) {
		for (ll k = zero; k<b.size(); k++) {
			for (ll j = zero; j<b[zero].size(); j++) {
				c[i][j] = mod((c[i][j] + product(a[i][k],b[k][j])), p);
			}
		}
	}
	return c;
}

vector<vector<ll>> pow(vector<vector<ll>>&a, ll n, ll p) {
	vector<vector<ll>>b(a.size(), vector<ll>(a.size()));
	for (ll i = zero; i<a.size(); i++) {
		b[i][i] = one;
	}
	while (n>zero) {
		if (n & one) b = mul(a, b, p);
		a = mul(a, a, p);
		n >>= one;
	}
	return b;
}

ll fibonacci(ll n, ll p) {
	vector<vector<ll>>a(two, vector<ll>(two));
	a[zero][zero] = one; a[zero][one] = one;
	a[one][zero] = one; a[one][one] = zero;
	a = pow(a, n + one, p);
	return a[one][zero];
}

int main() {
	int T; cin >> T;

	for (int i = zero; i < T; i++) {
		int N; cin >> N;
		
		cout << fibonacci(N-two, product(product(product(product(product(product(product(product(ten,ten),ten),ten),ten),ten),ten),ten),ten) + seven)
			+ fibonacci(N, product(product(product(product(product(product(product(product(ten, ten), ten), ten), ten), ten), ten), ten), ten) + seven) << endl;
	}

	return zero;
}
0