title: Primality Test Set 5Using Lucas Lehmer Series
signature: primalityTestSet5UsingLucasLehmerSeries(p) {
test_code: import 'dart:convert';
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(bool actual, bool expected){
      return actual.toString() == expected.toString();
  }
  
  String driver(p, bool expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(p), expected)){
              return "PASSED";
          }
          return "FAILED";
      }catch(exception_object){
          return exception_object.runtimeType.toString();
      }
  }
  
  int main() {
  
      print("TEST-0...${driver(
          11, 
          false)
      }");
  
      print("TEST-1...${driver(
          27, 
          false)
      }");
  
      print("TEST-2...${driver(
          31, 
          true)
      }");
  
      print("TEST-3...${driver(
          47, 
          false)
      }");
  
      print("TEST-4...${driver(
          3, 
          true)
      }");
  
      print("TEST-5...${driver(
          14, 
          false)
      }");
  
      print("TEST-6...${driver(
          41, 
          false)
      }");
  
      print("TEST-7...${driver(
          72, 
          false)
      }");
  
      print("TEST-8...${driver(
          39, 
          false)
      }");
  
      print("TEST-9...${driver(
          22, 
          false)
      }");
  
      return 0;
  }
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 );
  }