title: K Th Prime Factor Given Number
signature: class Solution {
  
      public Float kThPrimeFactorGivenNumber(Integer n, Integer k) {
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;
  }
question_info.extension: java
question_info.entry_fn_name: kThPrimeFactorGivenNumber
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": -1, "inputs": {"n": 94, "k": 0}}, {"idx": 1, "outputs": 3, "inputs": {"n": 99, "k": 1}}, {"idx": 2, "outputs": 2, "inputs": {"n": 64, "k": 3}}, {"idx": 3, "outputs": 3, "inputs": {"n": 27, "k": 3}}, {"idx": 4, "outputs": 3.0, "inputs": {"n": 24, "k": 4}}, {"idx": 5, "outputs": -1, "inputs": {"n": 84, "k": 6}}, {"idx": 6, "outputs": -1, "inputs": {"n": 69, "k": 98}}, {"idx": 7, "outputs": -1, "inputs": {"n": 69, "k": 39}}, {"idx": 8, "outputs": -1, "inputs": {"n": 22, "k": 60}}, {"idx": 9, "outputs": -1, "inputs": {"n": 39, "k": 57}}]
question_info.test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(Integer n, Integer k, Float expected){
          try{
              Driver driver = new Driver();
              if (driver.run(n, k,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(94, 0, -1.0f);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(99, 1, 3.0f);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(64, 3, 2.0f);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(27, 3, 3.0f);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(24, 4, 3.0f);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(84, 6, -1.0f);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(69, 98, -1.0f);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(69, 39, -1.0f);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(22, 60, -1.0f);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(39, 57, -1.0f);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(Integer n, Integer k, Float expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(n, k),expected);
      }
      
      public boolean validateSolution(Float actual, Float expected){
          return Math.abs(actual - expected) < 1e-06f;
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: java __FILENAME__