#include <bits/stdc++.h>
#define int long long
using namespace std;
const int P = 998244353;
int i2 = 499122177, i6 = 166374059;
const int mod = 998244353;
template <int mod>
struct typemod {
int val;
typemod(int a = 0) : val(a) {}
int inc(int a, int b) const { return (a + b) % mod; }
int dec(int a, int b) const { return (a - b) % mod; }
int mul(int a, int b) const { return (__int128)1 * a * b % mod; }
typemod<mod> operator+(const typemod<mod>& x) const {
return typemod(inc(val, x.val));
}
typemod<mod> operator-(const typemod<mod>& x) const {
return typemod(dec(val, x.val));
}
typemod<mod> operator*(const typemod<mod>& x) const {
return typemod(mul(val, x.val));
}
typemod<mod>& operator+=(const typemod<mod>& x) {
return *this = *this + x;
}
typemod<mod>& operator-=(const typemod<mod>& x) {
return *this = *this - x;
}
typemod<mod>& operator*=(const typemod<mod>& x) {
return *this = *this * x;
}
bool operator==(const typemod<mod>& x) const { return x.val == val; }
bool operator!=(const typemod<mod>& x) const { return x.val != val; }
};
typedef typemod<mod> Tm;
Tm two = 2;
struct ans {
ans() { f = g = h = 0; }
Tm f, g, h;
};
ans calc(Tm n, int a, int b, int c) {
Tm ac = a / c, bc = b / c, m = (a * n.val + b) / c, n1 = n + 1,
n21 = n * 2 + 1;
ans d;
if (a == 0) {
d.f = bc * n1;
d.g = bc * n * n1 * i2;
d.h = bc * bc * n1;
return d;
}
if (a >= c || b >= c) {
d.f = n * n1 * i2 * ac + bc * n1;
d.g = ac * n * n1 * n21 * i6 + bc * n * n1 * i2;
d.h = ac * ac * n * n1 * n21 * i6 + bc * bc * n1 + ac * bc * n * n1;
ans e = calc(n, a % c, b % c, c);
d.h += e.h + two * bc * e.f + two * ac * e.g;
d.g += e.g, d.f += e.f;
} else {
ans e = calc(m - 1, c, c - b - 1, a);
d.f = n * m - e.f;
d.g = m * n * n1 - e.h - e.f, d.g = (d.g * i2 + P);
d.h = n * m * (m + 1) - two * e.g - two * e.f - d.f;
}
d.f += P;
d.g += P;
d.h += P;
return d;
}
signed main() {
int T, n, a, b, c;
scanf("%lld", &T);
while (T--) {
scanf("%lld%lld%lld%lld", &n, &a, &b, &c);
ans ans = calc(n, a, b, c);
printf("%lld %lld %lld\n", ans.f, ans.h, ans.g);
}
return 0;
}
不知道怎么过不去,WA On #6 #7 80pts。
怀疑是typemod出锅了,求大佬调