結果

問題 No.554 recurrence formula
コンテスト
ユーザー 梧桐
提出日時 2026-01-23 01:18:43
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 545 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 696 ms
コンパイル使用メモリ 81,668 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-01-23 01:18:45
合計ジャッジ時間 1,886 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>

using namespace std;

typedef long long LL;

const int N = 100010, MOD = 1000000007;

int n;
LL a[N], s[2];

int main() {
    // freopen("seq.in", "r", stdin);
    // freopen("seq.out", "w", stdout);

    scanf("%d", &n);
    a[1] = s[1] = 1LL;
    for (int i = 2; i <= n; ++i) {
        if (i % 2 == 0) {
            a[i] = i * s[1] % MOD;
            (s[0] += a[i]) %= MOD;
        } else {
            a[i] = i * s[0] % MOD;
            (s[1] += a[i]) %= MOD;
        }
    }
    printf("%lld\n", a[n]);

    return 0;
}
0