Iamtui1010

phantichthanhthuasonguyento.cpp

Jun 8th, 2022
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<cstdlib>
  4. //#include<conio.h>
  5.  
  6. #define long long long
  7. #define nln '\n'
  8.  
  9. using namespace std;
  10.  
  11. vector<long> prm;
  12.  
  13. void sieve()
  14. {
  15.     long N = 1e4;
  16.     vector<bool> s(N, 0);
  17.     for (long i = 2; i <= N; ++i)
  18.         if (!s[i]){
  19.             prm.push_back(i);
  20.             for (long j = 2*i; j <= N; j += i)
  21.                 s[j] = 1;
  22.         }
  23. }
  24.  
  25.  
  26. void construe(long n)
  27. {
  28.     long i = 0;
  29.     while (n > 1){
  30.         if (n % prm[i] == 0){
  31.             cout << prm[i];
  32.             n /= prm[i];
  33.             if (n > 1)
  34.                 cout << "*";
  35.         }
  36.         else{
  37.             if (prm[i+1]*prm[i+1] > n){
  38.                 cout << n;
  39.                 n = 1;
  40.             }
  41.             ++i;
  42.         }
  43.         /*cout << "i: " << i << nln;
  44.         cout << "prm: " << prm[i] << nln;
  45.         cout << "n: " << n << nln;*/
  46. //      getch();
  47.     }
  48.     cout << nln;
  49. }
  50.  
  51. int main()
  52. {
  53.     cin.tie(0)->sync_with_stdio(0);
  54.     cout.tie(0)->sync_with_stdio(0);
  55.     //freopen("input.inp", "r", stdin);
  56.     //freopen("output.out", "w", stdout);
  57.     sieve();
  58.     long T;
  59.     cin >> T;
  60.     while (T--){
  61.         long n;
  62.         cin >> n;
  63.         construe(n);
  64.     }
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment