Advertisement
Salehisayev

FOR REVAN

Dec 31st, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. #define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  6. #define MAXX 10000005
  7.  
  8. int t , n;
  9.  
  10. bool p[MAXX];
  11. vector<int> v;
  12.  
  13. int main()
  14. {
  15.     _FastIO;
  16.     memset(p , true , sizeof(p));
  17.     for(int i = 2; i * i < MAXX; i++){
  18.         if(p[i])
  19.             for(int j = i + i; j < MAXX; j += i){
  20.                 p[j] = false;
  21.             }
  22.     }
  23.     v.push_back(2);
  24.     for(int i = 3; i < MAXX; i += 2){
  25.         if(p[i]) v.push_back(i);
  26.     }
  27.     cin >> t;
  28.     while(t--){
  29.         cin >> n;
  30.         if(p[n]){
  31.             cout << n << endl;
  32.             continue;
  33.         }
  34.         for(int i = 0; i < v.size(); i++){
  35.             int k = v[i];
  36.             while(!(n % k)){
  37.                 cout << k;
  38.                 n /= k;
  39.                 if(n != 1) cout << " * ";
  40.             }
  41.             if(n == 1) break;
  42.         }
  43.         cout << endl;
  44.     }
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement