fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using ll = long long;
  5. const int N = 2e5 + 5, mod = 1e9 + 7;
  6.  
  7. ll gcd(ll a, ll b) {
  8. return b == 0 ? a : gcd(b, a % b);
  9. }
  10. ll lcm(ll a, ll b) {
  11. return a / gcd(a, b) * b;
  12. }
  13.  
  14. int main()
  15. {
  16. ios_base::sync_with_stdio(false);
  17. cin.tie(nullptr);
  18.  
  19. for (int a = 1; a <= 9; a++) {
  20. for (int b = 1; b <= 9; b++) {
  21. // x + y = 10a + b
  22. // x * y = a + 10b
  23. // x * (10a + b - x) = a + 10b
  24. // x² - (10a + b)x + (a + 10b) = 0
  25. // x = [(10a + b) +- sqrt( (10a + b)² - 4(a + 10b) )] / 2a
  26.  
  27. int d = (10*a + b)*(10*a + b) - 4*(a + 10*b);
  28. if (d < 0) continue;
  29.  
  30. int sqrt_d = sqrt(d);
  31. if (sqrt_d * sqrt_d != d) continue;
  32.  
  33. int x = (10*a + b) + sqrt_d;
  34. if (x % (2)) continue;
  35.  
  36. x /= 2;
  37. int y = 10*a + b - x;
  38. cout << x << " " << y << endl;
  39. }
  40. }
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
9 9
24 3
47 2