fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define int long long
  5. #define yes cout << "YES\n";
  6. #define no cout << "NO\n";
  7.  
  8.  
  9. void FastIO(){
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(nullptr);
  12. cout.tie(nullptr);
  13. }
  14.  
  15. const int N = 1e6;
  16. vector<vector<int>> all(N+1);
  17.  
  18. void prime_factors(){
  19. all[0] = all[1] = {0};
  20. for(int k = 2; k <= N; k++){
  21. int n = k;
  22.  
  23. vector<int> ans;
  24. while (n % 2 == 0) {
  25. ans.push_back(2);
  26. n /= 2;
  27. }
  28.  
  29. for (int i = 3; i * i <= n; i += 2) {
  30. while (n % i == 0) {
  31. ans.push_back(i);
  32. n /= i;
  33. }
  34. }
  35. if (n > 1)
  36. ans.push_back(n);
  37. all[n] = ans;
  38. }
  39. }
  40.  
  41.  
  42. void solve(){
  43. int n;
  44. cin >> n;
  45.  
  46. vector<int>out = all[n];
  47.  
  48. for(int &i : out)
  49. cout << i << ' ';
  50. cout << '\n';
  51. }
  52.  
  53.  
  54. signed main(){
  55. FastIO();
  56. prime_factors();
  57.  
  58. int t = 1;
  59. cin >> t;
  60.  
  61. while (t--){
  62. solve();
  63. }
  64. return 0;
  65. }
Success #stdin #stdout 1.22s 29340KB
stdin
1
12
stdout