Advertisement
serega1112

1362

Jan 15th, 2021
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. class Solution:
  2.     def closestDivisors(self, num: int) -> List[int]:
  3.        
  4.         res = [1, num + 2]
  5.        
  6.         for i in range(1, 3):
  7.             cand = num + i
  8.             limit = math.floor(cand ** 0.5)
  9.             for j in range(limit, 0, -1):
  10.                 if cand % j == 0 and abs(j - cand // j) < abs(res[1] - res[0]):
  11.                     res = [cand // j, j]
  12.                     break
  13.                    
  14.         return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement