結果

問題 No.554 recurrence formula
ユーザー makonagix
提出日時 2017-08-28 00:58:49
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 557 bytes
コンパイル時間 452 ms
コンパイル使用メモリ 56,968 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-06 07:04:23
合計ジャッジ時間 1,240 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

long sumodd = 1;
long sumeven = 0;
int main(){
	long n;
	cin >> n;
	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}
	for (long i = 2; i <= n; i++) {
		if (i % 2 == 0) {
			long an = (i*sumodd) % 1000000007;
			if (i == n) {
				cout << an << endl;
				break;
			}
			sumeven = (sumeven + an) % 1000000007;
		}
		else {
			long an = (i*sumeven) % 1000000007;
			if (i == n) {
				cout << an << endl;
				break;
			}
			sumodd = (sumodd + an) % 1000000007;
		}
	}
	return 0;
}
0