classSolution:defkthFactor(self,n:int,k:int) ->int:for i inrange(1, n//2+1):if n % i ==0: k -=1if k ==0:return ireturn n if k ==1else-1
classSolution:defkthFactor(self,n:int,k:int) ->int: heap = []for x inrange(1, int(n**0.5) +1):if n % x ==0:heappush(heap, - x)iflen(heap)> k:heappop(heap)if x != n // x:heappush(heap, - n // x)iflen(heap)> k:heappop(heap)return-heappop(heap)if k ==len(heap)else-1