title: Primality Test Set 5Using Lucas Lehmer Series
signature: function primality_test_set_5using_lucas_lehmer_series(p)
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 );
  }
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(p, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(p) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver(11, false)
      print(string.format("TEST-0...%s",result))
  
      result = driver(27, false)
      print(string.format("TEST-1...%s",result))
  
      result = driver(31, true)
      print(string.format("TEST-2...%s",result))
  
      result = driver(47, false)
      print(string.format("TEST-3...%s",result))
  
      result = driver(3, true)
      print(string.format("TEST-4...%s",result))
  
      result = driver(14, false)
      print(string.format("TEST-5...%s",result))
  
      result = driver(41, false)
      print(string.format("TEST-6...%s",result))
  
      result = driver(72, false)
      print(string.format("TEST-7...%s",result))
  
      result = driver(39, false)
      print(string.format("TEST-8...%s",result))
  
      result = driver(22, false)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": false, "inputs": {"p": 11}}, {"idx": 1, "outputs": false, "inputs": {"p": 27}}, {"idx": 2, "outputs": true, "inputs": {"p": 31}}, {"idx": 3, "outputs": false, "inputs": {"p": 47}}, {"idx": 4, "outputs": true, "inputs": {"p": 3}}, {"idx": 5, "outputs": false, "inputs": {"p": 14}}, {"idx": 6, "outputs": false, "inputs": {"p": 41}}, {"idx": 7, "outputs": false, "inputs": {"p": 72}}, {"idx": 8, "outputs": false, "inputs": {"p": 39}}, {"idx": 9, "outputs": false, "inputs": {"p": 22}}]
question_info.extension: lua
question_info.entry_fn_name: primality_test_set_5using_lucas_lehmer_series
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: lua __FILENAME__