传送门
code
/*************************************************************************
> File Name: 1.cpp
> Author: Knowledge_llz
> Mail: 925538513@qq.com
> Blog: https://www.cnblogs.com/Knowledge-Pig/
************************************************************************/
#include<bits/stdc++.h>
#define LL long long
#define endl '\n'
using namespace std;
const int maxx = 1e6 + 10, mod = 998244353;
LL n, dp[maxx], sum[maxx], ans = 0;
int main(){
ios::sync_with_stdio(false); cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.out","w", stdout);
#endif
cin >> n;
dp[0] = sum[0] = 1;
for(int i = 1; i <= n; ++i){
dp[i] = sum[i - 1];
bool flag = 0;
for(int j = 22; j >= 0; --j){
if(i & (1 << j)){
if(!flag) flag = 1;
else (dp[i] -= (sum[(1 << (j + 1)) - 1] - sum[(1 << j) - 1])) %= mod;
}
}
sum[i] = (sum[i - 1] + dp[i]) % mod;
ans = (ans + dp[i]) % mod;
}
cout << (ans + mod) % mod << endl;
return 0;
}