結果
問題 | No.554 recurrence formula |
ユーザー |
![]() |
提出日時 | 2017-08-12 00:24:09 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 762 bytes |
コンパイル時間 | 732 ms |
コンパイル使用メモリ | 103,516 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-12 21:30:34 |
合計ジャッジ時間 | 1,456 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
import std.algorithm; import std.array; import std.conv; import std.math; import std.stdio; import std.string; import std.range; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.map!(to!int).array; } ulong calc(int n) { if (n == 1) return 1; const mod = 1_000_000_007; ulong sumOdd = 1; ulong sumEven = 0; ulong an = 0; for (int i = 2; i <= n; i++) { if (i % 2 == 0) { ulong ai = (i * sumOdd) % mod; sumEven += ai; an = ai; } else { ulong ai = (i * sumEven) % mod; sumOdd += ai; an = ai; } } return an; } void main() { int n = readint(); writeln(calc(n)); }