title: Primality Test Set 5Using Lucas Lehmer Series
signature: func primalityTestSet5UsingLucasLehmerSeries(p int) bool {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual bool, expected bool) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(p int, expected bool) string {
      if validateSolution(PLACEHOLDER_FN_NAME(p),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver(11, false)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver(27, false)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver(31, true)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver(47, false)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver(3, true)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver(14, false)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver(41, false)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver(72, false)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver(39, false)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver(22, false)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
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 );
  }