- /**
- 🍪 the_hyp0cr1t3
- 🍪 30.05.2021 04:20:37
- **/
- #ifdef W
- #include <k_II.h>
- #else
- #include <bits/stdc++.h>
- using namespace std;
- #endif
- #define pb emplace_back
- #define all(x) x.begin(), x.end()
- #define sz(x) static_cast<int32_t>(x.size())
-
- const int64_t k_II = 2e18;
- const int INF = 2e9, MOD = 1e9+7;
- const int N = 1e7 + 5;
-
- int main() {
- cin.tie(nullptr)->sync_with_stdio(false);
- int n;
- // spf is the smallest prime factor
- // precompute spf for all n using prime sieve (O(n loglogn))
- array<int, N> spf; iota(all(spf), 0);
- for(int z = 4; z < N; z += 2) spf[z] = 2;
- for(int z = 3; z*z < N; z += 2)
- if(spf[z] == z) for(int y = z*z; y < N; y += z*2)
- if(spf[y] == y) spf[y] = z;
-
- // Answer queries in O(log n) per query.
- // Log n because the maximum number of prime factors is log2 n.
- while(cin >> n) {
- cout << 1;
- while(n > 1) {
- cout << " x " << spf[n];
- n /= spf[n];
- } cout << '\n';
- }
-
- } // ~W