Skip to content

Practice The kth Factor of n

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1492
LeetCode Problem

The kth Factor of n

Problem Statement

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. Consider a list of all factors of n sorted in ascending order, return the kth factor in this list or return -1 if n has less than k factors. Example 1: Example 2: Example 3: Constraints: Follow up: Could you solve this problem in less than O(n) complexity?

Source: The kth Factor of n on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 12, k = 3
Output
3

# Example 2

Input
n = 7, k = 2
Output
7

# Example 3

Input
n = 4, k = 4
Output
-1

Constraints

1 <= k <= n <= 1000

Related LeetCode Problems

Practice more problems similar to The kth Factor of n.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.