title: Modular Exponentiation Power In Modular Arithmetic
signature: function modular_exponentiation_power_in_modular_arithmetic(x, y, p)
source_py: def modular_exponentiation_power_in_modular_arithmetic(x, y, p):
      res = 1
      x = (x % p)
      while (y > 0):
          if ((y & 1) == 1):
              res = ((res * x) % p)
          y = (y >> 1)
          x = ((x * x) % p)
      return res
source_cpp: int modular_exponentiation_power_in_modular_arithmetic(int x, unsigned int y, int p) {
    int res = 1;
    x = x % p;
    while ( y > 0 ) {
      if ( y & 1 ) res = ( res * x ) % p;
      y = y >> 1;
      x = ( x * x ) % p;
    }
    return res;
  }
question_info.entry_fn_name: modular_exponentiation_power_in_modular_arithmetic
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(x, y, p, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(x, y, p) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver(45, 5, 68, 61)
      print(string.format("TEST-0...%s",result))
  
      result = driver(67, 25, 49, 18)
      print(string.format("TEST-1...%s",result))
  
      result = driver(26, 91, 44, 4)
      print(string.format("TEST-2...%s",result))
  
      result = driver(33, 61, 9, 0)
      print(string.format("TEST-3...%s",result))
  
      result = driver(35, 8, 13, 3)
      print(string.format("TEST-4...%s",result))
  
      result = driver(68, 41, 5, 3)
      print(string.format("TEST-5...%s",result))
  
      result = driver(14, 76, 20, 16)
      print(string.format("TEST-6...%s",result))
  
      result = driver(5, 89, 13, 5)
      print(string.format("TEST-7...%s",result))
  
      result = driver(23, 42, 45, 19)
      print(string.format("TEST-8...%s",result))
  
      result = driver(37, 63, 56, 29)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 61, "inputs": {"x": 45, "y": 5, "p": 68}}, {"idx": 1, "outputs": 18, "inputs": {"x": 67, "y": 25, "p": 49}}, {"idx": 2, "outputs": 4, "inputs": {"x": 26, "y": 91, "p": 44}}, {"idx": 3, "outputs": 0, "inputs": {"x": 33, "y": 61, "p": 9}}, {"idx": 4, "outputs": 3, "inputs": {"x": 35, "y": 8, "p": 13}}, {"idx": 5, "outputs": 3, "inputs": {"x": 68, "y": 41, "p": 5}}, {"idx": 6, "outputs": 16, "inputs": {"x": 14, "y": 76, "p": 20}}, {"idx": 7, "outputs": 5, "inputs": {"x": 5, "y": 89, "p": 13}}, {"idx": 8, "outputs": 19, "inputs": {"x": 23, "y": 42, "p": 45}}, {"idx": 9, "outputs": 29, "inputs": {"x": 37, "y": 63, "p": 56}}]