title: Primality Test Set 5Using Lucas Lehmer Series
signature: fun primalityTestSet5UsingLucasLehmerSeries(p: Int): Boolean {
test_code: package main
  
  import kotlin.text.*
  import kotlin.math.*
  
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  fun validateSolution(actual:Boolean, expected:Boolean):Boolean{
    return actual.equals(expected)
  }
  fun driver(p: Int, expected:Boolean):String {
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME(p), expected)) {
                return "PASSED"
        }
        return "FAILED"
      } catch (e: Exception){
        return e::class.simpleName as String
      }
  
  }
  
  fun main() {
      var result: String = ""
      result = driver(11, false)
      println("TEST-0...${result}")
      
      result = driver(27, false)
      println("TEST-1...${result}")
      
      result = driver(31, true)
      println("TEST-2...${result}")
      
      result = driver(47, false)
      println("TEST-3...${result}")
      
      result = driver(3, true)
      println("TEST-4...${result}")
      
      result = driver(14, false)
      println("TEST-5...${result}")
      
      result = driver(41, false)
      println("TEST-6...${result}")
      
      result = driver(72, false)
      println("TEST-7...${result}")
      
      result = driver(39, false)
      println("TEST-8...${result}")
      
      result = driver(22, false)
      println("TEST-9...${result}")
      
          
  }
  
  main()
source_py: def primality_test_set_5using_lucas_lehmer_series(p):
      checkNumber = ((2 ** p) - 1)
      nextval = (4 % checkNumber)
      for i in range(1, (p - 1)):
          nextval = (((nextval * nextval) - 2) % checkNumber)
      if (nextval == 0):
          return True
      else:
          return False
source_cpp: bool primality_test_set_5using_lucas_lehmer_series(int p) {
    long long checkNumber = pow ( 2, p ) - 1;
    long long nextval = 4 % checkNumber;
    for ( int i = 1;
    i < p - 1;
    i ++ ) nextval = ( nextval * nextval - 2 ) % checkNumber;
    return ( nextval == 0 );
  }