結果

問題 No.720 行列のできるフィボナッチ数列道場 (2)
ユーザー ixmelixmel
提出日時 2017-06-24 21:41:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,688 bytes
コンパイル時間 2,249 ms
コンパイル使用メモリ 94,392 KB
実行使用メモリ 6,524 KB
最終ジャッジ日時 2023-07-27 10:07:29
合計ジャッジ時間 2,672 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
4,384 KB
testcase_01 AC 14 ms
5,076 KB
testcase_02 AC 17 ms
5,456 KB
testcase_03 AC 22 ms
6,116 KB
testcase_04 AC 24 ms
6,260 KB
testcase_05 AC 14 ms
4,980 KB
testcase_06 AC 15 ms
5,052 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 3 ms
4,384 KB
testcase_09 AC 7 ms
4,388 KB
testcase_10 AC 3 ms
4,388 KB
testcase_11 AC 8 ms
4,584 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 14 ms
6,236 KB
testcase_14 AC 12 ms
5,272 KB
testcase_15 AC 10 ms
4,992 KB
testcase_16 AC 13 ms
5,324 KB
testcase_17 AC 9 ms
4,900 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 16 ms
6,524 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 26 ms
6,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,string> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
#define MOD 1000000007
ll m;
vvi mul(vvi A,vvi B){
	vvi C(A.size(),vi(B[0].size()));
	rep(i,2)rep(j,m+1){
		C[i][j]=(A[i][0]*B[0][j]%MOD+A[i][1]*B[1][j]%MOD)%MOD;
	}
	(C[0][m]+=A[0][m])%=MOD;
	(C[1][m]+=A[1][m])%=MOD;
	return C;
}
vvi pow(vvi A,ll n){
	vvi B;
	bool h=false;
	while(n){
		if(n&1){
			if(h)B=mul(B,A);
			else B=A;
			h=true;
		}
		A=mul(A,A);
		n>>=1;
	}
	return B;
}
int main(){
	ll n;
	cin>>n>>m;
	assert(1<=n&&n<=10000000000ll&&2<=m&&m<=30000);
	vi A(m+1,1);
	vvi B(2,vi(m+1,1));
	A[m]=0;B[0][m-2]=2;B[1][m]=0;
	rep(i,m-2){
		A[m-i-3]=(A[m-i-2]+A[m-i-1])%MOD;
		rep(j,2)B[j][m-i-3]=(B[j][m-i-2]+B[j][m-i-1])%MOD;
	}
	vvi out=pow(B,n);
	cout<<(A[0]*out[0][m]%MOD+A[1]*out[1][m]%MOD)%MOD<<endl;
}










0