title: Modular Exponentiation Power In Modular Arithmetic
signature: func modularExponentiationPowerInModularArithmetic(x int, y int, p int) int {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual int, expected int) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(x int, y int, p int, expected int) string {
      if validateSolution(PLACEHOLDER_FN_NAME(x, y, p),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver(45, 
  	5, 
  	68, 61)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver(67, 
  	25, 
  	49, 18)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver(26, 
  	91, 
  	44, 4)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver(33, 
  	61, 
  	9, 0)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver(35, 
  	8, 
  	13, 3)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver(68, 
  	41, 
  	5, 3)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver(14, 
  	76, 
  	20, 16)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver(5, 
  	89, 
  	13, 5)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver(23, 
  	42, 
  	45, 19)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver(37, 
  	63, 
  	56, 29)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
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;
  }