結果

問題 No.534 フィボナッチフィボナッチ数
ユーザー ysuzuki5321ysuzuki5321
提出日時 2019-07-12 08:36:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,597 bytes
コンパイル時間 1,226 ms
コンパイル使用メモリ 98,784 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 06:37:11
合計ジャッジ時間 2,500 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 1 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~

ソースコード

diff #

#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
void add(long long& a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}
int a[30010];
int dp[30010];
ll getLIS()
{
	int P = 30010;
	fill(dp, dp + P, INF);
	for (int i = 0; i < P; ++i) {
		*lower_bound(dp, dp + P, a[i]) = a[i];
	}
	return lower_bound(dp, dp + P, INF) - dp;
}
ll memo[20][2];
ll calc(ll dig, ll v,int tite) {

	if (dig == 0) return 1;
	ll &res = memo[dig][tite];
	if (~res) return res;
	res = 0;
	ll p = pow(10, dig - 1);
	ll val = v / p;
	bool top = false;
	if (val < 10) {
		top = true;
	}else
		val = val % 10;
	if (tite == 1) {
		if (val == 4) {
			res = calc(dig - 1, v, 0) * (4);
		}
		else if (val < 4) {
			res = calc(dig - 1, v, 1);
			if (val > 0) {
				res += calc(dig - 1, v, 0) * val;
			}
		}
		else if (val == 9) {
			res = calc(dig - 1, v, 0) * (8);
		} 
		else {
			res = calc(dig - 1, v, 1);
			res += calc(dig - 1, v, 0) * (val - 1);
		}
	}
	else {
		res = calc(dig - 1, v, 0) * 8;
	}
	return res;
}

mat mulmat(mat a, mat b,ll mod) {
	mat c(a.size(), vec(b[0].size(),0));
	for (int i = 0; i < a.size(); i++)
	{
		for (int k = 0; k < b.size(); k++)
		{
			for (int j = 0; j < b[0].size(); j++)
			{
				c[i][j] += (a[i][k] * b[k][j]);
				c[i][j] %= mod;
			}
		}
	}
	return c;
}

mat p2mat(mat a,ll n,ll mod ) {
	mat b(a.size(), vec(a[0].size()));
	for (size_t i = 0; i < a.size(); i++)
	{
		b[i][i] = 1;
	}
	while (n > 0)
	{
		if (n & 1) b = mulmat (b,a,mod);
		a = mulmat(a, a,mod);
		n >>= 1;
	}
	return b;
}

void solv() {

	ll n;
	cin >> n;
	mat a(2, vec(2));
	a[0][0] = 1; a[0][1] = 1;
	a[1][0] = 1; a[1][1] = 0;
	mat r = p2mat(a, n, 2LL * 1e9 + 16);
	mat r2 = p2mat(a, r[1][0], INF);
	cout << r2[1][0] << endl;
}

int main() {
	//COMinit();
	solv();

	return 0;
}
0