結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー mannshi222
提出日時 2022-04-29 13:20:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 371 bytes
コンパイル時間 479 ms
コンパイル使用メモリ 66,104 KB
最終ジャッジ日時 2025-01-28 22:17:26
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;

int main()
{

	int N, M;
	cin >> N >> M;
	int F1 = 0;
	int F2 = 1;
	/*
	if( N == 0 ) {
		cout << F0 << endl;
		return 0;
	}
	if( N == 1 ) {
		cout << F1 << endl;
		return 0;
	}
	*/

	int tmp;
	for( int i = 1; i < N ; i++ ) {
		tmp = F1;
		F1 = F2;
		F2 = tmp + F1;
		F1 = F1%M;
		F2 = F2%M;
	}
	cout << F1 << endl;
	return 0;
}
0