title: Primality Test Set 5Using Lucas Lehmer Series
signature: function primalityTestSet5UsingLucasLehmerSeries(p) {
test_code: 
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function convertToString(value) {
      return JSON.stringify(value, function (key, val) {
          if (val instanceof Set) {
              return Array.from(val);
          } return val;});
  }
  
  function validateSolution(actual, expected){
      return convertToString(actual)===convertToString(expected);
  }
  
  function driver(p, expected){
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(p),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver(11, false);
    console.log(`TEST-0...${result}`);
  
    result = driver(27, false);
    console.log(`TEST-1...${result}`);
  
    result = driver(31, true);
    console.log(`TEST-2...${result}`);
  
    result = driver(47, false);
    console.log(`TEST-3...${result}`);
  
    result = driver(3, true);
    console.log(`TEST-4...${result}`);
  
    result = driver(14, false);
    console.log(`TEST-5...${result}`);
  
    result = driver(41, false);
    console.log(`TEST-6...${result}`);
  
    result = driver(72, false);
    console.log(`TEST-7...${result}`);
  
    result = driver(39, false);
    console.log(`TEST-8...${result}`);
  
    result = driver(22, false);
    console.log(`TEST-9...${result}`);
  
    process.exit(0);
  };
  
  if (require.main === module) {
    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 );
  }