Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prime Number Program in PHP w3schools
Sponsered Link
#1
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>"
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  PHP Function to Check Prime Number Kelly 0 146 08-19-2017, 05:04 AM
Last Post: Kelly

Forum Jump:


Users browsing this thread: 1 Guest(s)