#include<iostream> #include<cstdlib> usingnamespace std; typedeflonglong ll; constint maxn = 1000; constint N = 5; // 测试次数 constint C = 200; // 指定 find() 函数参数2 int T; ll factor[maxn], cnt; // 素因子和素因子的数目,下标从 1 开始 ll mini, m; ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll random(ll n) { return (ll)((double)rand() / RAND_MAX * n + 0.5); } ll multi(ll a, ll b, ll m)// a * b % m { ll ret = 0; while (b) { if (b & 1) ret = (ret + a) % m; b >>= 1; a = (a << 1) % m; } return ret; } ll quick_mod(ll a, ll b, ll m) { ll ans = 1; while (b) { if (b & 1) ans = multi(ans, a, m); b >>= 1; a = multi(a, a, m); } return ans; } boolWitness(ll a, ll n) { ll m = n - 1; int j = 0; while (!(m & 1)) { ++j; m >>= 1; } ll x = quick_mod(a, m, n); if (x == 1 || x == n - 1) returnfalse; while (j--) { x = x * x % n; if (x == n - 1) returnfalse; } returntrue; } boolmiller_rabin(ll n) { if (n == 2) returntrue; if (n < 2 || !(n & 1)) returnfalse; for (int i = 1; i <= N; ++i) { ll a = random(n - 2) + 1; if (Witness(a, n)) returnfalse; } returntrue; } ll pollard_rho(ll n, int c) { ll x, y, d, i = 1, k = 2; x = random(n - 1) + 1; y = x; while (true) { ++i; x = (multi(x, x, n) + c) % n; d = gcd(y - x, n); if (1 < d && d < n) return d; if (y == x) return n; if (i == k) { y = x; k <<= 1; } } } voidfind(ll n, int k) { if (n == 1) return ; if (miller_rabin(n)) { factor[++cnt] = n; mini = min(n, mini); return ; } ll p = n; while (p >= n) p = pollard_rho(p, k--); find(p, k); find(n / p, k); } intmain(void) { cin >> T; while (T--) { cin >> m; if (miller_rabin(m)) cout << "Prime" << endl; else { mini = __LONG_LONG_MAX__; find(m, C); cout << mini << endl; } } return0; }