結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー 👑 potato167potato167
提出日時 2020-12-08 15:06:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 631 bytes
コンパイル時間 1,773 ms
コンパイル使用メモリ 175,360 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 17:16:38
合計ジャッジ時間 2,878 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 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 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll I=167167167167;
ll Q=1e9+7;
ll M,N;
vector<vector<ll>> mul(vector<vector<ll>> a,vector<vector<ll>> b){
	vector<vector<ll>> c={{0,0},{0,0}};
	for(int i=0;i<2;i++){
		for(int k=0;k<2;k++){
			for(int j=0;j<2;j++){

					c[i][k]+=a[i][j]*b[j][k];
				
			}
			c[i][k]%=M;
		}
	}
	return c;
}
vector<vector<ll>> jyo(vector<vector<ll>> a,ll b){
	vector<vector<ll>> e={{1,0},{0,1}};
	while(b>0){
		if(b%2==1){
			e=mul(e,a);
		}
		a=mul(a,a);
		b/=2;
	}
	return e;
}
int main() {
	cin>>N>>M;
	vector<vector<ll>> p={{1,1},{1,0}};
	p=jyo(p,N-1);
	cout<<p[1][0]<<endl;
}
0