1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| #include <bits/stdc++.h>
using i64 = long long; template <class T> T qpow(__int128 a, T b, T p) { T res = 1; while (b) { if (b & 1) res = res * a % p; a = a * a % p; b >>= 1; } return res; } bool MillerRabin(i64 n) { if (n == 2) return true; if (n <= 1 || n % 2 == 0) return false; std::array<i64, 7> base {2, 235, 9375, 28178, 450775, 9780504, 1795265022}; i64 u = n - 1, k = 0; while (u % 2 == 0) { u /= 2; k++; } for (auto x : base) { if (x % n == 0) continue ; i64 v = qpow(x, u, n); if (v == 1 || v == n - 1) continue ; for (int j = 1; j <= k; j++) { i64 last = v; v = (__int128)v * v % n; if (v == 1) { if (last != n - 1) return false; break; } } if (v != 1) return false; } return true; }
i64 Pollard_Rho(i64 n) { static std::mt19937_64 sj(std::chrono::steady_clock::now().time_since_epoch().count()); std::uniform_int_distribution<i64> u0(1, n - 1);
i64 c = u0(sj); auto f = [&](i64 x) { return ((__int128)x * x + c) % n; }; i64 x = 0, y = 0, s = 1; for (int k = 1; ; k <<= 1, y = x, s = 1) { for (int i = 1; i <= k; i++) { x = f(x); s = (__int128)s * abs(x - y) % n; if (i % 127 == 0) { i64 d = std::gcd(s, n); if (d > 1) return d; } } i64 d = std::gcd(s, n); if (d > 1) return d; } return n; }
std::vector<i64> factor; void get(i64 n) { if (n == 1) return ; if (MillerRabin(n)) { factor.push_back(n); return ; }
i64 x = n; while (x == n) x = Pollard_Rho(n); get(x), get(n / x); }
void solve() { i64 n; std::cin >> n;
if (n == 1) { std::cout << "0\n"; return ; } factor.clear(); get(n); std::sort(factor.begin(), factor.end()); std::cout << factor.size() << " "; for (auto x : factor) { std::cout << x << " "; } std::cout << "\n"; }
int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int t; std::cin >> t;
while (t--) { solve(); } return 0; }
|