Class Solution
java.lang.Object
g1401_1500.s1492_the_kth_factor_of_n.Solution
1492 - The kth Factor of n.<p>Medium</p>
<p>You are given two positive integers <code>n</code> and <code>k</code>. A factor of an integer <code>n</code> is defined as an integer <code>i</code> where <code>n % i == 0</code>.</p>
<p>Consider a list of all factors of <code>n</code> sorted in <strong>ascending order</strong> , return <em>the</em> <code>k<sup>th</sup></code> <em>factor</em> in this list or return <code>-1</code> if <code>n</code> has less than <code>k</code> factors.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> n = 12, k = 3</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> Factors list is [1, 2, 3, 4, 6, 12], the 3<sup>rd</sup> factor is 3.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> n = 7, k = 2</p>
<p><strong>Output:</strong> 7</p>
<p><strong>Explanation:</strong> Factors list is [1, 7], the 2<sup>nd</sup> factor is 7.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> n = 4, k = 4</p>
<p><strong>Output:</strong> -1</p>
<p><strong>Explanation:</strong> Factors list is [1, 2, 4], there is only 3 factors. We should return -1.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= k <= n <= 1000</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
kthFactor
public int kthFactor(int n, int k)
-