P20863 [GeeksforGeeks] Kth prime factor of a number0132
普及-
题目描述

Given two numbers n and k, find the k^{th} prime factor of n.
Example 1:
Input: n = 225, k = 2
Output: 3
Explaination: The prime factors 3, 3, 5
and 5. So 3 is the 2nd one.
Example 2:
Input: n = 81, k = 5
Output: -1
Explaination: The 4 prime factors are
3, 3, 3, 3. So there is no 5th one.
Your Task:
You do not need to read input or print anything. Your task is to complete the function kthPrime() which takes the value n and k as input parameters and return the kth prime number. If k is greater than total number of primes then return -1.
Expected Time Complexity: O(n*log(log n))
Expected Auxiliary Space: O(n)
Constraints:
1 ≤ n ≤ 10^{4}
1 ≤ k ≤ 50

输入格式

见题面

输出格式

见题面

样例输入
n = 225, k = 2
样例输出
3