title: K Th Prime Factor Given Number
signature: func kThPrimeFactorGivenNumber(n int, k int) float64 {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual float64, expected float64) bool {
      return math.Abs(actual - expected) < 1e-06
  }
  
  func driver(n int, k int, expected float64) string {
      if validateSolution(PLACEHOLDER_FN_NAME(n, k),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver(94, 
  	0, -1.0)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver(99, 
  	1, 3.0)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver(64, 
  	3, 2.0)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver(27, 
  	3, 3.0)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver(24, 
  	4, 3.0)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver(84, 
  	6, -1.0)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver(69, 
  	98, -1.0)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver(69, 
  	39, -1.0)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver(22, 
  	60, -1.0)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver(39, 
  	57, -1.0)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
source_py: def k_th_prime_factor_given_number(n, k):
      while ((n % 2) == 0):
          k = (k - 1)
          n = (n / 2)
          if (k == 0):
              return 2
      i = 3
      while (i <= math.sqrt(n)):
          while ((n % i) == 0):
              if (k == 1):
                  return i
              k = (k - 1)
              n = (n / i)
          i = (i + 2)
      if ((n > 2) and (k == 1)):
          return n
      return (- 1)
source_cpp: int k_th_prime_factor_given_number(int n, int k) {
    while ( n % 2 == 0 ) {
      k --;
      n = n / 2;
      if ( k == 0 ) return 2;
    }
    for ( int i = 3;
    i <= sqrt ( n );
    i = i + 2 ) {
      while ( n % i == 0 ) {
        if ( k == 1 ) return i;
        k --;
        n = n / i;
      }
    }
    if ( n > 2 && k == 1 ) return n;
    return - 1;
  }