• PHP Video Tutorials

PHP - gmp_​prob_​prime() Function



Definition and Usage

The gmp_​prob_​prime() function checks if the GMP number is prime number or not.

Description

The gmp_​prob_​prime() function makes use of Miller-Rabin's probabilistic test to test if the given GMP number is prime or not.

Syntax

gmp_prob_prime ( GMP $a [, int $reps = 10 ] ) : int

Parameters

Sr.No Parameter & Description
1

a

The number to check if prime or not.It can a GMP resource number , a gmp object or a numeric string.

2

reps

The value of reps varies from 5 to 10.The default value is 10.

Return Values

PHP gmp_prob_prime() function a integer value, 0 means not a prime, 1 means probably prime and 2 means exact prime number.

PHP Version

This function will work from PHP Version greater than 5.0.0.

Example 1

Working of gmp_prob_prime() −

<?php
   $num = gmp_prob_prime("8162147");	
   if ($num === 2) {
      echo "Prime Number";
   } else if ($num === 1) {
      echo "Probably Prime Number";
   } else {
      echo "Not a Prime Number";	
   }
?>

This will produce following result −

Not a Prime Number

Example 2

Working of gmp_powm() −

<?php
   $num = gmp_prob_prime("229");	
   if ($num === 2) {
      echo "Prime Number";
   } else if ($num === 1) {
      echo "Probably Prime Number";
   } else {
      echo "Not a Prime Number";	
   }
?>

This will produce following result −

Prime Number
php_function_reference.htm
Advertisements