package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/closest-divisors/
 */
public class Problem1362 {
    public int[] closestDivisors(int num) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1362 prob = new Problem1362();
        System.out.println(Arrays.toString(prob.closestDivisors(8))); // [3,3]
        System.out.println(Arrays.toString(prob.closestDivisors(123))); // [5,25]
        System.out.println(Arrays.toString(prob.closestDivisors(999))); // [40,25]
        System.out.println(Arrays.toString(prob.closestDivisors(10))); // [3,4]
    }
}

@@ -16,34 +16,8 @@
 e;%0A%0A
-import java.util.Arrays;%0A%0A
 /**%0A
@@ -154,458 +154,711 @@
     
-// TODO%0A        return null
+int a = num + 1;%0A        int b = num + 2
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1362 prob = new Problem1362()
+int%5B%5D div1 = divisor(a);%0A        int diff1 = Math.abs(div1%5B0%5D - div1%5B1%5D);%0A        int%5B%5D div2 = divisor(b);%0A        int diff2 = Math.abs(div2%5B0%5D - div2%5B1%5D);%0A        return diff1 %3C diff2 ? div1 : div2
 ;%0A    
+%7D%0A%0A
     
-System.out.println(Arrays.toString(prob.closestDivisors(8))); // %5B3,3%5D%0A        System.out.println(Arrays.toString(prob.closestDivisors(123))); // %5B5,25%5D%0A        System.out.println(Arrays.toString(prob.closestDivisors(999))); // %5B40,25%5D%0A        System.out.println(Arrays.toString(prob.closestDivisors(10))); // %5B3,4%5D
+private static int%5B%5D divisor(int num) %7B%0A        int%5B%5D div = new int%5B2%5D;%0A        int min = Integer.MAX_VALUE;%0A        for (int i = 1; i %3C= Math.sqrt(num); i++) %7B%0A            if (num %25 i == 0) %7B%0A                int diff = Math.abs(i - (num / i));%0A                if (diff %3C min) %7B%0A                    div%5B0%5D = i;%0A                    div%5B1%5D = num / i;%0A                    min = diff;%0A                %7D%0A            %7D%0A        %7D%0A        return div;
 %0A   

Solve problem 1362