結果
| 問題 | No.554 recurrence formula |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-09-08 11:09:22 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 452 bytes |
| 記録 | |
| コンパイル時間 | 1,184 ms |
| コンパイル使用メモリ | 210,000 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-06-06 18:10:42 |
| 合計ジャッジ時間 | 2,177 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:22:16: warning: 'b' may be used uninitialized [-Wmaybe-uninitialized]
22 | else cout << b << endl;
| ^
main.cpp:11:14: note: 'b' was declared here
11 | int a = 1, b;
| ^
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int MOD = int(1e9) + 7;
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
int odd = 1, even = 0;
int a = 1, b;
for (int i = 2; i <= n; ++i) {
if (i & 1) {
a = 1LL * i * even % MOD;
odd = (odd + a) % MOD;
} else {
b = 1LL * i * odd % MOD;
even = (even + b) % MOD;
}
}
if (n & 1) cout << a << endl;
else cout << b << endl;
return 0;
}