Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://www.facebook.com/CungHocLapTrinhUIT
- #include <iostream>
- using namespace std;
- bool SNT(int n)
- {
- if (n < 2) return false;
- for (int i = 2; i <= sqrt(float(n)); i++)
- {
- if (n % i == 0) return false;
- }
- return true;
- }
- int test(int n)
- {
- int arr[100];
- int size = 0;
- for (int i = 2; i <= sqrt(float(n)); i++)
- {
- if (SNT(i) && n % i == 0)
- {
- arr[size++] = i;
- n = n / i;
- i--;
- }
- }
- if (size > 0)
- {
- cout << n;
- for (int i = size - 1; i >= 0; i--)
- cout << " x " << arr[i];
- }
- else
- cout << n;
- cout << endl;
- return 0;
- }
- int main()
- {
- int n;
- cin >> n;
- int arr[10000];
- for (int i = 0; i < n; i++)
- {
- cin >> arr[i];
- }
- for (int i = 0; i < n; i++)
- test(arr[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement