class PrimeNumbers: def __init__(self, nmax): from math import isqrt rootnmax = isqrt(nmax) self.prime_judgement = [True]*(rootnmax+1) self.prime_judgement[0] = self.prime_judgement[1] = False for i in range(2, rootnmax+1): if self.prime_judgement[i]: for j in range(2, rootnmax//i+1): self.prime_judgement[i*j] = False self.prime_list = [] for i, flag in enumerate(self.prime_judgement): if flag: self.prime_list.append(i) def prime_factorization(self, n): return_list = [] for i in self.prime_list: if n == 1 or i*i > n: break if n%i == 0: return_list.append([i, 0]) while n%i == 0: return_list[-1][1] += 1; n //= i if n != 1: return_list.append([n, 1]) return return_list def number_of_divisors(self, n): num = 1 for _, v in self.prime_factorization(n): num *= v+1 return num from sys import setrecursionlimit from functools import lru_cache setrecursionlimit(10**6) @lru_cache() def main(n): m = n-pn.number_of_divisors(n) return main(m) if m else n pn = PrimeNumbers(10**9) for _ in range(int(input())): print(main(int(input())))