Forum Discussion

Full Version: Prime Number Program in PHP w3schools
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Prime Number Program in PHP

gmp_nextprime— Find next prime number

PHP Code:
$var1 gmp_nextprime(9); // it will return next prime number greater than 9
$var2 gmp_nextprime(-999); // it will return next prime number greater than -999

echo gmp_strval($var1) . "<br>";
echo 
gmp_strval($var2) . "<br>"

gmp_prob_prime — Check if number is "probably prime".
The function uses Miller-Rabin's probabilistic test to check if a number is a prime.
It will 0 for not a prime number and 1 for probably a prime number and 2 for definitely a prime number.

PHP Code:
// It is definitely not a prime
echo gmp_prob_prime("6") . "<br>";

// It is probably a prime
echo gmp_prob_prime("1111111111111111111") . "<br>";

// It is definitely a prime
echo gmp_prob_prime("11") . "<br>"