#pragma region Macros #pragma GCC target("avx", "avx2") #pragma GCC optimize("-O3", "unroll-loops") #include using namespace std; #if __has_include() #include #include #include #include #include #include #include #include #include #include #include using namespace atcoder; #endif using ll= long long; using ld= long double; using ull= unsigned long long; using i128= __int128; using pll= pair; using vi= vector; using vl= vector; using vd= vector; using vs= vector; using vi128= vector; using vpll= vector; using vvi= vector; using vvl= vector; using vvd= vector; using vvs= vector; using vvi128= vector; using vvpll= vector; #if __has_include() using mint= modint1000000007; // using mint = modint998244353; using vm= vector; using vvm= vector; #endif constexpr ll mod= 1e9 + 7; // constexpr ll mod= 998244353; #define ALL(x) (x).begin(), (x).end() #define _overload3(_1, _2, _3, name, ...) name #define REPBASE(i, a, b) for(ll i= (a), i##_b= (b); i < i##_b; i++) #define RREPBASE(i, a, b) for(ll i= (a), i##_b= (b); i >= i##_b; i--) #define LOOP(n) REPBASE(i##__COUNTER__##_##__LINE__, 0, n) #define REPB(i, n) REPBASE(i, 0, n) #define REPS(i, n) REPBASE(i, 1, n + 1) #define RREP(i, n) RREPBASE(i, n - 1, 0) #define RREPS(i, n) RREPBASE(i, n, 1) #define REP(...) _overload3(__VA_ARGS__, REPBASE, REPB, LOOP)(__VA_ARGS__) #define EACH(x, c) for(auto &x : c) #define PERM(p) \ sort(ALL(p)); \ for(bool(p##c)= 1; (p##c); (p##c)= next_permutation(ALL(p))) #define eb emplace_back #define mp make_pair #define fi first #define se second #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) template inline ll SZ(const T &x) { return x.size(); } ll TOPBIT(const ll &t) { return (t == 0 ? -1 : 63 - __builtin_clzll(t)); } ll BIT(const ll &n) { return (1LL << n); } template inline string YES(const T &n) { return (n ? "YES" : "NO"); } template inline string Yes(const T &n) { return (n ? "Yes" : "No"); } template inline string yes(const T &n) { return (n ? "yes" : "no"); } template inline void UNIQUE(T &v) { v.erase(unique(ALL(v)), v.end()); } template inline ll LB(const T &v, const U &x) { return distance(v.begin(), lower_bound(ALL(v), x)); } template inline ll UB(const T &v, const U &x) { return distance(v.begin(), upper_bound(ALL(v), x)); } template inline bool chmax(T &a, const T &b) { if(a < b) { a= b; return 1; } return 0; } template inline bool chmin(T &a, const T &b) { if(b < a) { a= b; return 1; } return 0; } const vpll dx4{{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; const vpll dx8{{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}}; #define VEC(name, size, ...) \ vector<__VA_ARGS__> name(size); \ IN(name) #define VV(name, h, w, ...) \ vector> name((h), vector<__VA_ARGS__>(w)); \ IN(name) #define LL(...) \ ll __VA_ARGS__; \ IN(__VA_ARGS__) #define STR(...) \ string __VA_ARGS__; \ IN(__VA_ARGS__) #define LD(...) \ ld __VA_ARGS__; \ IN(__VA_ARGS__) #define I128(...) \ i128 __VA_ARGS__; \ IN(__VA_ARGS__) void _scan() {} template void _scan(pair &p) { _scan(p.fi), _scan(p.se); } template void _scan(T &a) { cin >> a; } void IN() {} template void IN(Head &head, Tail &...tail) { _scan(head); IN(tail...); } #if __has_include() inline ostream &operator<<(ostream &stream, const mint &m) { stream << m.val(); return stream; } #endif template inline istream &operator>>(istream &stream, vector &v) { EACH(x, v) stream >> x; return stream; } template inline ostream &operator<<(ostream &stream, const vector &v) { ll sz= SZ(v); REP(i, sz) { stream << v[i] << (i == sz - 1 ? "" : " "); } return stream; } template inline ostream &operator<<(ostream &stream, const vector> &v) { ll sz= SZ(v); REP(i, sz) { stream << v[i] << (i == sz - 1 ? "" : "\n"); } return stream; } template inline istream &operator>>(istream &stream, pair &p) { stream >> p.fi >> p.se; return stream; } template inline ostream &operator<<(ostream &stream, const pair &p) { stream << p.fi << " " << p.se; return stream; } template inline pair operator+(pair p, const pair &q) { p+= q; return p; } template inline pair &operator+=(pair &p, const pair &q) { p.fi+= q.fi; p.se+= q.se; return p; } template inline pair operator-(pair p, const pair &q) { p-= q; return p; } template inline pair &operator-=(pair &p, const pair &q) { p.fi-= q.fi; p.se-= q.se; return p; } template inline pair operator+(const pair &p) { return p; } template inline pair operator-(const pair &p) { return mp(-p.fi, -p.se); } inline i128 parse(string &s) { reverse(ALL(s)); i128 ret= 0; bool minus= 0; if(*(s.rbegin()) == '-') { minus= 1; s.pop_back(); } while(!s.empty()) { if('0' <= *(s.rbegin()) && *(s.rbegin()) <= '9') { ret= ret * 10 + *(s.rbegin()) - '0'; s.pop_back(); } else { break; } } reverse(ALL(s)); if(minus) ret*= -1; return ret; } inline string to_string(i128 val) { string ret= ""; bool minus= 0; if(val < 0) { minus= 1; val*= -1; } do { int digit= val % 10; ret+= to_string(digit); val/= 10; } while(val != 0); if(minus) ret+= "-"; reverse(ALL(ret)); return ret; } inline istream &operator>>(istream &stream, i128 &val) { string str; stream >> str; val= parse(str); while(!str.empty()) { stream.putback(*(str.rbegin())); str.pop_back(); } return stream; } inline ostream &operator<<(ostream &stream, const i128 &val) { stream << to_string(val); return stream; } inline void print() { cout << "\n"; } template inline void print(const Head &H, const Tail &...T) { cout << H; (cout << ... << (cout << " ", T)); cout << endl; } inline void debug_out() { cout << "\n"; } template inline void debug_out(const Head &H, const Tail &...T) { cout << H; (cout << ... << (cout << " ", T)); cout << endl; } #ifdef _DEBUG #define debug(...) debug_out(__VA_ARGS__) #else #define debug(...) #endif #pragma endregion /* safe_mod */ /* O(1) */ constexpr ll safe_mod(ll x, const ll &m= mod) { x%= m; if(x < 0) x+= m; return x; } /* modpow */ /* O(logN) */ /* requirement : safe_mod */ constexpr ll modpow(ll a, ll b, ll m= mod) { ll res= 1; for(a= safe_mod(a, m); b; a= i128(a) * a % m, b>>= 1) { if(b & 1) res= i128(res) * a % m; } return res % m; } /* Miller-Rabin primality test */ /* requirement : safe_mod, modpow */ /* O(logN) */ bool miller_rabin(const ll &n) { if(n <= 1) return 0; if(n <= BIT(31)) { if(n == 2 || n == 7 || n == 61) return 1; if(n % 2 == 0) return 0; vl bases= {2, 7, 61}; ll d= n - 1; while(d % 2 == 0) d/= 2; for(ll a : bases) { if(n <= a) break; ll t= d; a= modpow(a, d, n); while(t != n - 1 && a != 1 && a != n - 1) { a= a * a % n; t<<= 1; } if(a != n - 1 && t % 2 == 0) { return 0; } } return 1; } else { vl bases= {2, 325, 9375, 28178, 450775, 9780504, 1795265022}; if(n % 2 == 0) return 0; ll d= n - 1; while(d % 2 == 0) d/= 2; for(ll a : bases) { ll t= d; a= modpow(a, d, n); while(t != n - 1 && a != 1 && a != n - 1) { a= i128(a) * a % n; t<<= 1; } if(a != n - 1 && t % 2 == 0) return 0; } return 1; } } vl prime_factor(ll n) { vl ret= {}; while(~n & 1) { ret.eb(2); n/= 2; } while(n % 3 == 0) { ret.eb(3); n/= 3; } while(n % 5 == 0) { ret.eb(5); n/= 5; } for(ll i= 0; i < 100; i+= 30) { vl ps= {1, 7, 11, 13, 17, 19, 23, 29}; REP(l, 8) { if(i + l == 0) continue; while(n % (i + ps[l]) == 0) { ret.eb(i + ps[l]); n/= i + ps[l]; } } } if(n == 1) { return ret; } else if(miller_rabin(n)) { ret.eb(n); return ret; } else { queue que; que.emplace(n); while(!que.empty()) { // 非自明な約数を探す ll a= que.front(); que.pop(); ll m= 128; for(ll c= 1;; ++c) { ll g= 1; i128 y= 2, x, q= 1, ys; for(ll r= 1; g == 1; r<<= 1) { x= y; REP(i, r) y= (y * y + c) % a; for(ll k= 0; k < r && g == 1; k+= m) { ys= y; REP(min(m, r - k)) { y= (y * y + c) % a; q*= x - y; q%= a; } q= abs((ll)q); g= gcd((ll)q, a); debug(c, r, k, q, g, a); } } if(g == a) { g= 1; while(g == 1) { ys= (ys * ys + c) % a; g= gcd(abs(ll(x - ys)), a); debug(g, ys); } } if(g < a) { if(miller_rabin(g)) { ret.eb(g); } else { que.emplace(g); } if(miller_rabin(a / g)) { ret.eb(a / g); } else { que.emplace(a / g); } break; } } } sort(ALL(ret)); return ret; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12); LL(Q); REP(Q) { LL(A); print(A, miller_rabin(A)); } // print(miller_rabin(3896644057)); // REP(Q) { // LL(A); // vl fact= prime_factor(A); // print(SZ(fact),fact); // } }