PROBLEM LINK:
Contest Division 1
Contest Division 2
Contest Division 3
Contest Division 4
Setter: Lavish Gupta
Tester: Nishank Suresh, Utkarsh Gupta
Editorialist: Pratiyush Mishra
DIFFICULTY:
1666
PREREQUISITES:
None
PROBLEM:
For two positive integers a and b, let g(a, b) = gcd
(a, b) + lcm(a, b).
For a positive integer N, let f(N) denote the minimum value of g(a, b) over all the pairs of positive integers (a, b) such that a+b = N.
Find out the number of ordered pairs (a, b) such that a+b = N and g(a, b) = f(N).
EXPLANATION:
Observation 1: For all 1 \leq a \leq N, which are factors of N,
Proof:
By the property
We can write
Also using the property
we get,
which is the minimum value we can get. To prove this let us assume a is not a factor of N.
Then g(a,N-a) = gcd(a,N-a) + \frac{a(N-a)}{gcd(a,N-a)}.
Let us assume:
Simplifying it we get
Since gcd(a,b) \leq min(a,b), therefore we can see that the first term of L will always be \leq 0 while the second term will always be \geq 0, so we conclude that
Thus we can select all possible factors of N as a and b would be (N-a). This way we can find all possible pairs (a,b) that gives minimum value of g(a,b).
TIME COMPLEXITY:
O(\sqrt{N}), for each test case.
SOLUTION:
Editorialist’s Solution
Setter’s Solution
Tester1’s Solution
Tester2’s Solution