fork(4) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int q(int n) {
  5. int a, b, a1, b1, i, f, am, bm;
  6.  
  7. a = 1;
  8. b = n;
  9.  
  10. for (a1 = 2; a1 < n; a1++) {
  11. if (n % a1) continue;
  12. for (b1 = a1 + 1; b1 < n; b1++) {
  13. if (n % b1) continue;
  14. am = n / a1;
  15. bm = n / b1;
  16. f = 1;
  17. for (i = 2; i <= bm; i++) {
  18. if ((am % i == 0) && (bm % i == 0)) {
  19. f = 0;
  20. break;
  21. }
  22. }
  23. if (f) {
  24. if ((b - a) > (b1 - a1)) {
  25. a = a1;
  26. b = b1;
  27. }
  28. }
  29. }
  30. }
  31.  
  32. cout << "n=" << n << " a=" << a << " b=" << b << endl;
  33. return 0;
  34. }
  35.  
  36. int main() {
  37. // your code goes here
  38. q(360);
  39. q(1000);
  40. q(720);
  41. q(2018);
  42. q(36);
  43.  
  44. return 0;
  45. }
  46.  
  47.  
Success #stdin #stdout 0s 4528KB
stdin
Standard input is empty
stdout
n=360  a=36  b=40
n=1000  a=200  b=250
n=720  a=45  b=48
n=2018  a=2  b=1009
n=36  a=9  b=12