結果

問題 No.2903 A Round-the-World Trip with the Tent
コンテスト
ユーザー vwxyz
提出日時 2024-09-27 21:09:23
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 925 ms / 2,000 ms
コード長 736 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,077 ms
コンパイル使用メモリ 180,268 KB
実行使用メモリ 192,000 KB
最終ジャッジ日時 2026-04-14 14:46:19
合計ジャッジ時間 12,063 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
#define int long long

const int MOD = 998244353;

signed main() {
    int N;
    long long K;  // K is long long
    cin >> K >> N;

    vector<vector<int>> D(N + 1);
    for (int d = 1; d <= N; ++d) {
        for (int n = 2 * d; n <= N; n += d) {
            D[n].push_back(d);
        }
    }
    long long pow2=2;
    vector<int> dp(N + 1, 0);
    for (int n = 1; n <= N; ++n) {
        dp[n] = pow2 % MOD;
        pow2*=2;
        pow2%=MOD;
        if (K > 1) {
            dp[n] += 1;
        }
        for (int d : D[n]) {
            dp[n] = (dp[n] - dp[d] + MOD) % MOD;
        }
    }

    int ans = dp[N];
    cout << ans << endl;

    return 0;
}
0