Nearest Composite Number
Problem statement
Return the composite integer with the smallest absolute difference from n. A composite integer is greater than 1 and has a divisor other than 1 and itself.
If two composite numbers are equally near, return the smaller one.
Function
nearestComposite(n: int) → intExamples
Example 1
n = 4return = 4Case 1 exercises the documented deterministic contract.
Example 2
n = 5return = 4Case 2 exercises the documented deterministic contract.
Example 3
n = 7return = 6Case 3 exercises the documented deterministic contract.
Constraints
0 <= n <= 10^9.