Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5761 |

@blackshadows | 5715 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 1115 |

@bt8816103042 | 739 |

@thealchemist627 | 456 |

@akashkale117 | 453 |

@shivanandp12345678910 | 453 |

@dalwainazism125 | 453 |

@codeantik | 448 |

@SherlockHolmes3 | 447 |

@SHOAIBVIJAPURE | 430 |

@shalinibhataniya1097 | 408 |

@neverevergiveup | 393 |

Complete Leaderboard |

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

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Kth Prime Factor

...