#include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; #include using namespace atcoder; using mint = modint998244353; bool isflg(int k, ll x) { return ((1LL << k) & x); } int main() { ll N;cin >> N; int K = 60; mint res = 0; for (int k = 0;k <= K;k++) { vector> dp(K + 1, vector(2, 0)); dp[0][0] = 1; for (int i = K;i >= 0;i--) { vector> ndp(K + 1, vector(2, 0)); for (int p = 0;p <= K;p++) { if (i == k) { if (p+1 <= K) { ndp[p + 1][1] += dp[p][1]; if (isflg(k, N)) { ndp[p + 1][0] += dp[p][0]; } } continue; } ndp[p][1] += dp[p][1]; if (p+1 <= K) { ndp[p + 1][1] += dp[p][1]; } if (!isflg(i, N)) { ndp[p][0] += dp[p][0]; } else { ndp[p][1] += dp[p][0]; if (p+1 <= K) { ndp[p + 1][0] += dp[p][0]; } } } swap(dp, ndp); } for (int t = 0;t <= K;t++) { mint sm = dp[t][0] + dp[t][1]; mint a = (1LL << k); sm = (sm * (sm +1)) / 2; res += a * sm; } } cout << res.val() << endl; }