結果

問題 No.554 recurrence formula
ユーザー horiesiniti
提出日時 2018-03-27 15:32:29
言語 Ruby
(3.4.1)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 216 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-06-25 12:48:19
合計ジャッジ時間 3,017 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n=gets.to_i
a1=1
a2=0
a1sum=1
a2sum=0
mod=10**9+7
(n).times{|i|
	m=i+2
	if i%2==0
		a2=(a1sum*m)%mod
		a2sum=(a2sum+a2)%mod
	else
		a1=(a2sum*m)%mod
		a1sum=(a1sum+a1)%mod
	end
}

if n%2==0
	puts a2
else
	puts a1
end
0