1492. The kth Factor of n Medium
1/**
2 * [1492] The kth Factor of n
3 *
4 * You are given two positive integers n and k. A factor of an integer n is defined as an integer i where n % i == 0.
5 * Consider a list of all factors of n sorted in ascending order, return the k^th factor in this list or return -1 if n has less than k factors.
6 *
7 * Example 1:
8 *
9 * Input: n = 12, k = 3
10 * Output: 3
11 * Explanation: Factors list is [1, 2, 3, 4, 6, 12], the 3^rd factor is 3.
12 *
13 * Example 2:
14 *
15 * Input: n = 7, k = 2
16 * Output: 7
17 * Explanation: Factors list is [1, 7], the 2^nd factor is 7.
18 *
19 * Example 3:
20 *
21 * Input: n = 4, k = 4
22 * Output: -1
23 * Explanation: Factors list is [1, 2, 4], there is only 3 factors. We should return -1.
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= k <= n <= 1000
29 *
30 *
31 * Follow up:
32 * Could you solve this problem in less than O(n) complexity?
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/the-kth-factor-of-n/
38// discuss: https://leetcode.com/problems/the-kth-factor-of-n/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn kth_factor(n: i32, k: i32) -> i32 {
44 0
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_1492() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.