Mid/SeniorMath
Closest Divisors
Given an integer num, find the closest two integers in absolute difference whose product equals num + 1 or num + 2.
Return the two integers in any order.
Example 1
Input
num = 8Output
[3,3]For
num + 1 = 9, the closest divisors are 3 and 3; for num + 2 = 10, the closest divisors are 2 and 5, so [3, 3] is chosen.Example 2
Input
num = 123Output
[5,25]The closest valid pair is
5 and 25, whose product equals num + 2 = 125.Constraints
- 1 <= num <= 10^9