text: Primality Test | Set 5 ( Using Lucas | Function to check whether / ( 2 ^ p - 1 ) is prime or not . ; generate the number ; First number of the series ; Generate the rest ( p - 2 ) terms of the series . ; now if the ( p - 1 ) th term is 0 return true else false . ; Driver Code Check whether 2 ^ p - 1 is prime or not .
code: < ? php function isPrime ( $ p ) { $ checkNumber = pow ( 2 , $ p ) - 1 ; $ nextval = 4 % $ checkNumber ; for ( $ i = 1 ; $ i < $ p - 1 ; $ i ++ ) $ nextval = ( $ nextval * $ nextval - 2 ) % $ checkNumber ; return ( $ nextval == 0 ) ; } $ p = 7 ; $ checkNumber = pow ( 2 , $ p ) - 1 ; if ( isPrime ( $ p ) ) echo $ checkNumber , " ▁ is ▁ Prime . " ; else echo $ checkNumber , " ▁ is ▁ not ▁ Prime . " ; ? >