Advertisement
huutho_96

test

Oct 30th, 2015
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. //https://www.facebook.com/CungHocLapTrinhUIT
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. bool SNT(int n)
  6. {
  7.     if (n < 2) return false;
  8.     for (int i = 2; i <= sqrt(float(n)); i++)
  9.     {
  10.         if (n % i == 0) return false;
  11.     }
  12.     return true;
  13. }
  14.  
  15. int test(int n)
  16. {
  17.     int arr[100];
  18.     int size = 0;
  19.  
  20.     for (int i = 2; i <= sqrt(float(n)); i++)
  21.     {
  22.         if (SNT(i) && n % i == 0)
  23.         {
  24.             arr[size++] = i;
  25.             n = n / i;
  26.             i--;
  27.         }
  28.     }
  29.     if (size > 0)
  30.     {
  31.         cout << n;
  32.         for (int i = size - 1; i >= 0; i--)
  33.             cout << " x " << arr[i];
  34.     }
  35.     else
  36.         cout << n;
  37.     cout << endl;
  38.     return 0;
  39. }
  40.  
  41. int main()
  42. {
  43.     int n;
  44.     cin >> n;
  45.     int arr[10000];
  46.     for (int i = 0; i < n; i++)
  47.     {
  48.         cin >> arr[i];
  49.     }
  50.     for (int i = 0; i < n; i++)
  51.         test(arr[i]);
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement