結果

問題 No.554 recurrence formula
ユーザー eigoroli
提出日時 2017-08-12 00:46:40
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 609 bytes
コンパイル時間 1,285 ms
コンパイル使用メモリ 159,412 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-12 22:37:38
合計ジャッジ時間 2,053 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n;
ll MOD = 1000000007;
ll a[100005];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	ll s1 = 1, s2 = 0;
	a[1] = 1;
	for (int i = 2; i <= n; i++) {
		if (i & 1) {
			a[i] = i * s2 % MOD;
			s1 = (s1 + a[i]) % MOD;
		}
		else {
			a[i] = i * s1 % MOD;
			s2 = (s2 + a[i]) % MOD;
		}
	}
	cout << a[n] << endl;

	return 0;
}
0