fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(0);
  7.  
  8. int n;
  9. cin >> n;
  10. vector<int> a(n), d1(n, -1), d2(n, -1);
  11.  
  12. for (int i = 0; i < n; ++i) cin >> a[i];
  13.  
  14. for (int i = 0; i < n; ++i) {
  15. int x = a[i];
  16. vector<int> divisors;
  17.  
  18. for (int d = 2; d * d <= x; ++d) {
  19. if (x % d == 0) {
  20. divisors.push_back(d);
  21. if (d != x / d) divisors.push_back(x / d);
  22. }
  23. }
  24.  
  25. int found = 0;
  26. for (int j = 0; j < (int)divisors.size(); ++j) {
  27. for (int k = j + 1; k < (int)divisors.size(); ++k) {
  28. int p = divisors[j], q = divisors[k];
  29. if (__gcd(p + q, x) == 1) {
  30. d1[i] = p;
  31. d2[i] = q;
  32. found = 1;
  33. break;
  34. }
  35. }
  36. if (found) break;
  37. }
  38. }
  39.  
  40. for (int x : d1) cout << x << ' ';
  41. cout << '\n';
  42. for (int x : d2) cout << x << ' ';
  43. cout << '\n';
  44.  
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0s 5328KB
stdin
10
2 3 4 5 6 7 8 9 10 24
stdout
-1 -1 -1 -1 2 -1 -1 -1 2 2 
-1 -1 -1 -1 3 -1 -1 -1 5 3