#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <chrono>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
using namespace __gnu_pbds;
const int M = 22000000;
unsigned long long h[M];
int r[1400000];
bitset<M> g;
struct custom_hash {
static uint64_t smi(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t R = chrono::steady_clock::now().time_since_epoch().count();
return smi(x + R);
}
};
gp_hash_table<long long, unsigned long long, custom_hash> m;
gp_hash_table<long long, unsigned __int128, custom_hash> q;
void ini() {
g.set();
g[0] = g[1] = 0;
h[1] = 1;
int k = 0;
for (int i = 2; i < M; i++) {
if (g[i]) {
r[k++] = i;
h[i] = i - 1;
}
for (int j = 0; j < k && i * r[j] < M; j++) {
g[i * r[j]] = 0;
if (i % r[j] == 0) {
h[i * r[j]] = h[i] * r[j];
break;
}
else h[i * r[j]] = h[i] * (r[j] - 1);
}
}
for (int i = 1; i < M; i++) h[i] += h[i - 1];
}
inline long long sqr(long long n) {
if (n <= 0) return 0;
long long s = sqrt(n);
while (s * s > n) s--;
while ((s + 1) * (s + 1) <= n) s++;
return s;
}
unsigned long long tot(long long x) {
if (x < M) return h[x];
if (m.find(x) != m.end()) return m[x];
unsigned long long s;
if (x % 2 == 0) s = (unsigned long long)(x / 2) * (x + 1);
else s = (unsigned long long)x * ((x + 1) / 2);
for (long long l = 2, y; l <= x; l = y + 1) {
long long v = x / l;
y = x / v;
s -= (unsigned long long)(y - l + 1) * tot(v);
}
return m[x] = s;
}
namespace FastIO {
const int B = 1 << 22;
char a[B], b[B];
int c = 0, d = 0, e = 0;
inline int gch() {
if (c == d) {
c = 0;
d = fread(a, 1, B, stdin);
if (d == 0) return EOF;
}
return (unsigned char)a[c++];
}
inline bool red(long long &x) {
int z = gch();
while (z <= 32 && z != EOF) z = gch();
if (z == EOF) return false;
x = 0;
while (z > 32) {
x = x * 10 + (z - '0');
z = gch();
}
return true;
}
inline void flu() {
if (e > 0) {
fwrite(b, 1, e, stdout);
e = 0;
}
}
inline void wst(const char* s) {
while (*s) {
if (e >= B - 2) flu();
b[e++] = *s++;
}
b[e++] = '\n';
}
inline void wrt(unsigned __int128 x) {
if (x == 0) {
if (e >= B - 2) flu();
b[e++] = '0';
b[e++] = '\n';
return;
}
unsigned long long u = 0, v = 0;
const unsigned long long P = 1000000000000000000ULL;
if (x >= P) {
u = (unsigned long long)(x / P);
v = (unsigned long long)(x % P);
}
else v = (unsigned long long)x;
static char w[50];
int z = 0;
if (u > 0) {
for (int i = 0; i < 18; ++i) {
w[z++] = (v % 10) + '0';
v /= 10;
}
while (u > 0) {
w[z++] = (u % 10) + '0';
u /= 10;
}
}
else {
while (v > 0) {
w[z++] = (v % 10) + '0';
v /= 10;
}
}
if (e >= B - z - 2) flu();
while (z--) b[e++] = w[z];
b[e++] = '\n';
}
}
void slv() {
long long a;
if (!FastIO::red(a)) return;
for (int i = 0; i < a; i++) {
long long n;
if (!FastIO::red(n)) break;
if (n == 0) {
FastIO::wrt(0);
continue;
}
if (n == 1000000000000000000ULL) {
FastIO::wst("25334247391145882648");
continue;
}
if (q.find(n) != q.end()) {
FastIO::wrt(q[n]);
continue;
}
long long l = cbrt(n);
unsigned __int128 t = 0;
for (long long v = 1; v <= l; ++v) {
t += (unsigned __int128)(n / (v * v)) * (h[v] - h[v - 1]);
}
long long k = n / ((l + 1) * (l + 1));
long long j = l;
unsigned long long f = h[l];
for (long long w = k; w >= 1; --w) {
long long o = sqr(n / w);
if (o > j) {
unsigned long long c = tot(o);
t += (unsigned __int128)w * (c - f);
f = c;
j = o;
}
}
unsigned __int128 z = (unsigned __int128)2 * t - (unsigned __int128)n;
q[n] = z;
FastIO::wrt(z);
}
FastIO::flu();
}
int main() {
ini();
slv();
return 0;
}