結果

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

ソースコード

diff #

#include<cstdio>
#include<vector>


using namespace std;
using ll=long long;
using vll=vector<ll>;
using vvll=vector<vll>;


#define MOD 1000000007


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vll a(n+1), s(n+1);

		a[1]=1;
		s[1]=1;
		for(int i=2;i<=n;i++)
		{
			a[i]=(i*s[i-1])%MOD;
			s[i]=(s[i-2]+a[i])%MOD;
		}
		printf("%lld\n", a[n]);
	}

	return 0;
}
0