結果
| 問題 | No.554 recurrence formula |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-23 01:03:35 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 664 bytes |
| 記録 | |
| コンパイル時間 | 570 ms |
| コンパイル使用メモリ | 81,276 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-01-23 01:03:37 |
| 合計ジャッジ時間 | 1,577 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include <iostream>
using namespace std;
const int MOD = 1e9 + 7;
int n, odd_sum, even_sum;
int main() {
// freopen("seq.in", "r", stdin);
// freopen("seq.out", "w", stdout);
scanf("%d", &n);
odd_sum = 1;
if (n == 1) {
puts("1");
return 0;
}
for (int i = 2; i <= n; ++i) {
int x;
if (i % 2 == 0) {
x = 1LL * i * odd_sum % MOD;
even_sum = (0LL + even_sum + x) % MOD;
} else {
x = 1LL * i * even_sum % MOD;
odd_sum = (0LL + odd_sum + x) % MOD;
}
if (i == n) {
printf("%d\n", x);
}
}
return 0;
}