import math import sys def compute_T(k, N): if k == 0: return 0 if k == 1: return N low = 1 high = N best = 0 while low <= high: mid = (low + high) // 2 product = 1 overflow = False for _ in range(k): product *= mid if product > N: overflow = True break if overflow: high = mid - 1 else: best = mid low = mid + 1 return best def count_perfect_powers(T): if T < 2: return 0 perfect = set() max_e = 1 while (2 ** (max_e + 1)) <= T: max_e += 1 for e in range(2, max_e + 1): x_max = compute_T(e, T) if x_max < 2: continue for x in range(2, x_max + 1): pe = x ** e if pe > T: continue perfect.add(pe) return len(perfect) def solve(): input = sys.stdin.read().split() T_cases = int(input[0]) cases = list(map(int, input[1:T_cases+1])) for N in cases: ans = N * N # Contribution from t=1 if N == 0: print(0) continue max_k = 1 while (2 ** max_k) <= N: max_k += 1 max_k -= 1 if max_k < 1: print(ans) continue for k1 in range(1, max_k + 1): T1 = compute_T(k1, N) for k2 in range(1, max_k + 1): T2 = compute_T(k2, N) T = min(T1, T2) if T < 2: continue perfect = count_perfect_powers(T) non_perfect = T - 1 - perfect if non_perfect <= 0: continue g = math.gcd(k1, k2) s1 = (N * g) // k2 s2 = (N * g) // k1 s_max = min(s1, s2) if s_max < 1: continue ans += non_perfect * s_max print(ans) if __name__ == "__main__": solve()