Redaksiya
Let’s consider the values that the expression takes, where for fixed and . For example, .
Let’s consider, for instance, the function . Then
According to the extended Euclidean algorithm, there always exist integers and , such that . Therefore, the smallest positive value that the expression can take is . From this, it follows that this expression can take all possible values of the form , where .
Theorem. If , then this function takes values of the form , where .
Proof. Indeed,
Since the numbers and are coprime, there always exists integers and such that the numerator of the fraction equals . Therefore, the function can take all possible values of the form , where .
Now let's consider the original function
Its values are the distances from the point to the nearest point of the form , where . To maximize the function , the value of should be chosen so that it is exactly in the middle between the neighboring points and , where is an integer. The value of the function at such a point is , which will be the answer.
Example
Let . It is obvious that . The equality holds because there exist integers and such that (for example, ). From this, it also follows that , where .
However, , and this will be the maximum value of the function, as the point is at the maximum distance from the zeros of the function.
Algorithm realization
The gcd function computes the greatest common divisor of the numbers and .
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
The lcm function computes the least common multiple of the numbers and .
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
The main part of the program. Read the input data.
while (scanf("%lld %lld", &n, &m) == 2) {
Compute and print the result.
d = 2 * lcm(n, m); printf("%lld/%lld\n", 1, d); }