title: K Th Prime Factor Given Number
signature: function kThPrimeFactorGivenNumber(n: number, k: number): number {
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.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.entry_cls_name: Solution
question_info.test_code: 
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function convertToString(value: any): string{
      return JSON.stringify(value, function (key, val) {
          if (val instanceof Set) {
              return Array.from(val);
          } return val;});
  }
  
  function validateSolution(actual: number, expected: number): boolean {
      return Math.abs(actual - expected) < 1e-06;
  }
  
  function driver(n: number, k: number, expected:number): string {
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(n, k),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver(94, 0, -1.0);
    console.log(`TEST-0...${result}`);
  
    result = driver(99, 1, 3.0);
    console.log(`TEST-1...${result}`);
  
    result = driver(64, 3, 2.0);
    console.log(`TEST-2...${result}`);
  
    result = driver(27, 3, 3.0);
    console.log(`TEST-3...${result}`);
  
    result = driver(24, 4, 3.0);
    console.log(`TEST-4...${result}`);
  
    result = driver(84, 6, -1.0);
    console.log(`TEST-5...${result}`);
  
    result = driver(69, 98, -1.0);
    console.log(`TEST-6...${result}`);
  
    result = driver(69, 39, -1.0);
    console.log(`TEST-7...${result}`);
  
    result = driver(22, 60, -1.0);
    console.log(`TEST-8...${result}`);
  
    result = driver(39, 57, -1.0);
    console.log(`TEST-9...${result}`);
  
  };
  
  main();
question_info.extension: ts
question_info.entry_fn_name: kThPrimeFactorGivenNumber
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: tsc --target es2020 --lib es5,dom,es2015,es2020 __FILENAME__
question_info.commands: node __FILENAME__.js