#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using Int = long long; template ostream &operator<<(ostream &os, const pair &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template ostream &operator<<(ostream &os, const vector &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; } template void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } #define COLOR(s) ("\x1b[" s "m") #ifndef LIBRA_OTHER_INT128_H_ #define LIBRA_OTHER_INT128_H_ #include #include constexpr unsigned __int128 toUInt128(const char *s) { unsigned __int128 x = 0; for (; *s; ++s) x = x * 10 + (*s - '0'); return x; } constexpr __int128 toInt128(const char *s) { if (*s == '-') return -toInt128(s + 1); __int128 x = 0; for (; *s; ++s) x = x * 10 + (*s - '0'); return x; } unsigned __int128 inUInt128() { static char buf[41]; scanf("%s", buf); return toUInt128(buf); } __int128 inInt128() { static char buf[41]; scanf("%s", buf); return toInt128(buf); } void out(unsigned __int128 x) { static char buf[41]; int len = 0; do { buf[len++] = '0' + static_cast(x % 10); } while (x /= 10); for (int i = len; --i >= 0; ) putchar(buf[i]); } void out(__int128 x) { if (x < 0) { putchar('-'); out(-static_cast(x)); } else { out(static_cast(x)); } } std::ostream &operator<<(std::ostream &os, unsigned __int128 x) { static char buf[41]; int len = 0; do { buf[len++] = '0' + static_cast(x % 10); } while (x /= 10); for (int i = len; --i >= 0; ) os << buf[i]; return os; } std::ostream &operator<<(std::ostream &os, __int128 x) { if (x < 0) { os << '-' << -static_cast(x); } else { os << static_cast(x); } return os; } #endif // LIBRA_OTHER_INT128_H_ __int128 solve(unsigned long long N) { if (N == 0) return 0; // const unsigned long long N2 = sqrt(static_cast(N)); unsigned long long M2 = sqrtl(N); for (; (unsigned __int128)2*M2*M2 + M2 + M2 < N; ++M2) {} for (; (unsigned __int128)2*M2*M2 + M2 + M2 > N; --M2) {} unsigned long long N3 = cbrt(static_cast(N)); for (; static_cast(N3) * N3 * N3 < N; ++N3) {} for (; static_cast(N3) * N3 * N3 > N; --N3) {} unsigned long long M3 = N3; // ? __int128 sum = 0; // \sum[1<=y<=floor(N^(1/2))] floor(N/y) using Pt = pair; // { (x, y) | x y > N }: convex region auto inside = [&](unsigned long long x, unsigned long long y) -> bool { // return (static_cast(x) * y > N); // return ((unsigned __int128)2*x*y + x + y > N); return (2*x*y + x + y > N); // ? }; // -(slope at x) <= p.y/p.x auto steep = [&](unsigned long long x, const Pt &p) -> bool { // return (static_cast(N) * p.first <= static_cast(p.second) * x * x); // (2N+1) / (2x+1)^2 <= p.y/p.x return ((unsigned __int128)(2*N + 1) * p.first <= (unsigned __int128)p.second * (2*x + 1) * (2*x + 1)); }; vector stack{{1, 0}, {1, 1}}; // (x, y): inside // unsigned long long x = N / N2, y = N2 + 1; unsigned long long x = (N - M2) / (2*M2 + 1), y = M2 + 1; assert(inside(x, y)); for (; ; ) { Pt l = stack.back(); stack.pop_back(); for (; inside(x + l.first, y - l.second); x += l.first, y -= l.second) { // (x, y) -> (x + l.x, y - l.y) // sum for [y - l.y, y) sum += x * l.second + (l.first - 1) * (l.second + 1) / 2; } // if (y <= N3) break; if (y <= M3) break; Pt r = l; for (; l = stack.back(), !inside(x + l.first, y - l.second); stack.pop_back()) r = l; // (x, y) + l: inside, (x, y) + r: outside for (; ; ) { const Pt m(l.first + r.first, l.second + r.second); if (inside(x + m.first, y - m.second)) { stack.push_back(l = m); } else { if (steep(x + m.first, l)) break; r = m; } } } // for (; --y; ) sum += N / y; for (; --y; ) sum += (N - y) / (2*y + 1); // return 2 * sum - N2 * N2; return 2 * sum - M2 * M2; } //////////////////////////////////////////////////////////////////////////////// int main() { for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) { unsigned long long N; scanf("%llu", &N); const __int128 ans = solve(N); out(ans % 998244353); puts(""); } #ifndef LOCAL break; #endif } return 0; }