You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
773 B
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
ll a, b;
cin >> a >> b;
if (a > b) swap(a, b);
ll dif = abs(a - b);
if (dif == 0)
{
cout << 0 << endl;
return 0;
}
ll r = dif / a;
//ll k = (dif - a % dif) % dif;
ll k = a % (dif % a);
cout << k << endl;
pair<ll, ll> ans = {numeric_limits<ll>::max(), 0};
for (int i = 0; i < 1000000; i++)
ans = min(ans, {lcm(a + i, b + i), i});
cout << ans.first << " " << ans.second << endl;
return 0;
}