title: Primality Test Set 5Using Lucas Lehmer Series
signature: def primalityTestSet5UsingLucasLehmerSeries(p: Int) = {
test_code: import scala.collection.mutable.HashMap
  import scala.collection.immutable.HashSet
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  
  // TESTING CODE 
  // ============================================
  def validateSolution(actual: Boolean , expected: Boolean): Boolean = {
      actual.toString == expected.toString
  }
  
  def driver(p: Int, expected: Boolean): String = {
      try {
          if (validateSolution(PLACEHOLDER_FN_NAME(p),expected)) {
              "PASSED"
          } else{
              "FAILED"
          }
      }catch{
          case e: Exception => {e.getClass.getName}
      }
  
  }
  object QuestionEvaluator extends App {
  
      println(s"TEST-0...${driver(
        11, 
        false    
      )}")   
  
  
      println(s"TEST-1...${driver(
        27, 
        false    
      )}")   
  
  
      println(s"TEST-2...${driver(
        31, 
        true    
      )}")   
  
  
      println(s"TEST-3...${driver(
        47, 
        false    
      )}")   
  
  
      println(s"TEST-4...${driver(
        3, 
        true    
      )}")   
  
  
      println(s"TEST-5...${driver(
        14, 
        false    
      )}")   
  
  
      println(s"TEST-6...${driver(
        41, 
        false    
      )}")   
  
  
      println(s"TEST-7...${driver(
        72, 
        false    
      )}")   
  
  
      println(s"TEST-8...${driver(
        39, 
        false    
      )}")   
  
  
      println(s"TEST-9...${driver(
        22, 
        false    
      )}")   
  
  }
  
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 );
  }