1. /**
  2. 🍪 the_hyp0cr1t3
  3. 🍪 30.05.2021 04:20:37
  4. **/
  5. #ifdef W
  6. #include <k_II.h>
  7. #else
  8. #include <bits/stdc++.h>
  9. using namespace std;
  10. #endif
  11. #define pb emplace_back
  12. #define all(x) x.begin(), x.end()
  13. #define sz(x) static_cast<int32_t>(x.size())
  14. const int64_t k_II = 2e18;
  15. const int INF = 2e9, MOD = 1e9+7;
  16. const int N = 1e7 + 5;
  17. int main() {
  18. cin.tie(nullptr)->sync_with_stdio(false);
  19. int n;
  20. // spf is the smallest prime factor
  21. // precompute spf for all n using prime sieve (O(n loglogn))
  22. array<int, N> spf; iota(all(spf), 0);
  23. for(int z = 4; z < N; z += 2) spf[z] = 2;
  24. for(int z = 3; z*z < N; z += 2)
  25. if(spf[z] == z) for(int y = z*z; y < N; y += z*2)
  26. if(spf[y] == y) spf[y] = z;
  27. // Answer queries in O(log n) per query.
  28. // Log n because the maximum number of prime factors is log2 n.
  29. while(cin >> n) {
  30. cout << 1;
  31. while(n > 1) {
  32. cout << " x " << spf[n];
  33. n /= spf[n];
  34. } cout << '\n';
  35. }
  36. } // ~W