MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / Solution

Class Solution

LeetCode_problems/kth_factor_of_n/solution.py:2–13  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1# This the main class for the solution
2class Solution: # This class takes two integer n and k as input
3 def kthFactor(self, n: int, k: int) -> int: # Here n is the number and k is the kth factor.
4 ls = [] # Initialize the empty list
5 i = 1
6 while(i<=n): # In this while loop we append all the factors of the number n
7 if n%i == 0:
8 ls.append(i) # Appending the number to the list.
9 i += 1
10 try: # Returns the Kth factor if exist
11 return ls[k-1]
12 except: # else returns -1
13 return -1

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected