fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define int long long
  4. using namespace std;
  5. const int maxn = 1e6+7;
  6. ll n,k,ans=LLONG_MIN,pre[maxn],a,b;
  7. vector<ll> uoc;
  8. void sanguoc()
  9. {
  10. for (int i=1;i*i<=b;i++)
  11. {
  12. if (b % i == 0)
  13. {
  14. uoc.push_back(i);
  15. if (b/i != i) uoc.push_back(b/i);
  16. }
  17. }
  18. }
  19. ll lcm(ll x, ll y)
  20. {
  21. return x / __gcd(x,y) * y;
  22. }
  23. int32_t main()
  24. {
  25. ios_base::sync_with_stdio(false);
  26. cin.tie(NULL);
  27. freopen("HOCTOAN.INP","r",stdin);
  28. freopen("HOCTOAN.OUT","w",stdout);
  29. cin >> a >> b;
  30. sanguoc();
  31. sort(uoc.begin(),uoc.end());
  32. ll ma = LLONG_MAX,ans1=-1,ans2=-1,miX=LLONG_MAX;
  33. for (auto x:uoc)
  34. {
  35. for (auto y:uoc)
  36. {
  37. if (__gcd(x,y) == a && lcm(x,y) == b)
  38. {
  39. ll sum = x+y;
  40. if (sum < ma)
  41. {
  42. ma = sum;
  43. miX = x;
  44. ans1 = x;
  45. ans2 = y;
  46. }
  47. else if (sum == ma)
  48. {
  49. if (x < miX)
  50. {
  51. miX = x;
  52. ans1 = x;
  53. ans2 = y;
  54. }
  55. }
  56. }
  57. }
  58. }
  59. if (ans1 != -1 && ans2 != -1) cout << ma << '\n' << ans1 << ' ' << ans2;
  60. else cout << -1;
  61. return 0;
  62. }
  63.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty