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
Inputnum = 8
Output[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
Inputnum = 123
Output[5,25]
The closest valid pair is 5 and 25, whose product equals num + 2 = 125.

Constraints

  • 1 <= num <= 10^9

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate