汉明的重量

想起还有道CF计数题没补…

题意是求,jls的取模整数板子好像有些问题。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <bits/stdc++.h>
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
*/
using namespace std;

const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;

#define f(i, a, b) for (int i = a; i <= b; i++)
#define scan(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define lowbit(x) (x & (-x))

#define fi first
#define se second
#define SZ(x) int((x).size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define summ(a) (accumulate(all(a), 0ll))

typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

using ll = long long;
// assume -P <= x < 2P
const int P = 998244353, mod = P;

int powmod(int a, int b)
{
int res = 1;
for (; b > 0; b >>= 1, a = 1ll * a * a % mod)
if (b & 1)
res = 1ll * res * a % mod;
return res;
}

template <int MOD, int RT>
struct mint
{
static const int mod = MOD;
static constexpr mint rt() { return RT; } // primitive root for FFT
int v;
explicit operator int() const { return v; } // explicit -> don't silently convert to int
mint() : v(0) {}
mint(ll _v)
{
v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD);
if (v < 0)
v += MOD;
}
bool operator==(const mint &o) const
{
return v == o.v;
}
friend bool operator!=(const mint &a, const mint &b)
{
return !(a == b);
}
friend bool operator<(const mint &a, const mint &b)
{
return a.v < b.v;
}

mint &operator+=(const mint &o)
{
if ((v += o.v) >= MOD)
v -= MOD;
return *this;
}
mint &operator-=(const mint &o)
{
if ((v -= o.v) < 0)
v += MOD;
return *this;
}
mint &operator*=(const mint &o)
{
v = int((ll)v * o.v % MOD);
return *this;
}
mint &operator/=(const mint &o) { return (*this) *= inv(o); }
friend mint pow(mint a, ll p)
{
mint ans = 1;
assert(p >= 0);
for (; p; p /= 2, a *= a)
if (p & 1)
ans *= a;
return ans;
}
friend mint inv(const mint &a)
{
assert(a.v != 0);
return pow(a, MOD - 2);
}

mint operator-() const { return mint(-v); }
mint &operator++() { return *this += 1; }
mint &operator--() { return *this -= 1; }
friend mint operator+(mint a, const mint &b) { return a += b; }
friend mint operator-(mint a, const mint &b) { return a -= b; }
friend mint operator*(mint a, const mint &b) { return a *= b; }
friend mint operator/(mint a, const mint &b) { return a /= b; }
};

using Z = mint<mod, 3>;
Z inv2;
Z cal(ll n)
{
Z ans = Z(n)*Z(n+1)*inv2*61;
for (int i = 0; i < 61; ++i)
{
ll bs = 1ll << (i + 1);
ll cnt = n / bs;
Z qsb = 0;
if(cnt){
qsb += Z(cnt) * Z(bs * (cnt - 1)) * Z((1ll<<i)) * inv2;
qsb += Z(cnt) * Z(1ll<<i) * Z((1ll<<i)-1) * inv2;
}
ll nxt=n;
if (n & (1ll << i))nxt=nxt/(1ll << i)*((1ll << i))-1ll;

{
Z fr = nxt / bs * bs;
Z bkcn =( nxt & ((1ll<<i) - 1)) + 1ll;
//cerr<<fr<<"::"<<(nxt & ((1ll<<i) - 1))<<"\n";
qsb += (bkcn) * Z(fr);
qsb += (bkcn) * (bkcn - 1) * inv2;
}

ans -= qsb;
}
return ans;
}
ll tt, n;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
inv2=inv(Z(2));
cin >> tt;
f(sb, 1, tt)
{
cin >> n;
cout << (cal(n)).v << "\n";
}
return 0;
}