asgarlikanan

https://www.e-olymp.com/az/problems/3261

Aug 7th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
4CS 0.49 KB | None | 0 0
  1. /*
  2.     Author: Kanan Asgarli
  3.     https://www.e-olymp.com/az/problems/3261
  4. */
  5. #include <iostream>
  6. #include <cmath>
  7.  
  8. using namespace std;
  9. int n, t, f;
  10. int main()
  11. {
  12.     cin>>t;
  13.     while(t--){
  14.         cin>>n;
  15.         f = 0;
  16.         for(int i = 2; i <= sqrt(n); i++ )
  17.             while( n % i == 0 ){
  18.                 n = n / i;
  19.                 if( f == 0 )
  20.                     cout<<i;
  21.                 else
  22.                     cout<<" * "<<i;
  23.                 f = 1;
  24.             }
  25.         if( n > 1 ){
  26.             if( f == 1 )
  27.                 cout<<" * "<<n;
  28.             else
  29.                 cout<<n;
  30.         }
  31.     cout<<endl;
  32.     }
  33.     return 0;
  34. }
Add Comment
Please, Sign In to add comment