The gmp_prob_prime() is a built-in function in PHP which is used to check how much is the possibility of given GMP number(GNU Multiple Precision : For large numbers) to be prime or not.
This function uses Miller-Rabin primality test to check if the given GMP number is prime or not.
Syntax:
gmp_prob_prime($num)
Parameters: The function accepts a GMP number $num as mandatory parameter as shown in the above syntax. This parameter can be a GMP object in PHP version 5.6 and later, or we are also allowed to pass numeric string such that it is possible to convert this string in number.
Return Value: This function returns value in the range 0-2, 0 if the number is definitely not prime, 1 if the number may be prime else 2 if the number is surely prime.
Examples:
Input : gmp_prob_prime("8")
Output : 0
Input : gmp_prob_prime("11111111111111")
Output : 1
Input: gmp_prob_prime("127")
Output: 2
Below programs illustrate the gmp_prob_prime() function in PHP:
Program 1: Program to find the prime probability of GMP number when numeric strings as GMP numbers are passed as arguments.
<?php // PHP program to find the prime probability of // GMP numbers passed as arguments // strings as GMP numbers $num = "17"; // calculate the possibility // of GMP number to be prime $prob = gmp_prob_prime($num); echo $prob; ?> |
Output:
2
Program 2: Program to find the prime probability of GMP number when GMP numbers are passed as arguments.
<?php // PHP program to find the prime probability of // GMP numbers passed as arguments // creating GMP numbers using gmp_init() $num = gmp_init(8); // calculate the possibility of // GMP number to be prime $prob = gmp_prob_prime($num); echo $prob; ?> |
Output:
0
Program 3: Program to find the prime probability of GMP number when GMP numbers are passed as arguments.
<?php // PHP program to find the prime probability of // GMP numbers passed as arguments // creating GMP numbers using gmp_init() $num = gmp_init(1111111111111111111); // calculate the possibility of // GMP number to be prime $prob = gmp_prob_prime($num); echo $prob; ?> |
Output:
1
Reference:
php.net/manual/en/function.gmp-prob-prime.php
Recommended Posts:
- How to get the function name inside a function in PHP ?
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- PHP | imagecreatetruecolor() Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- PHP | Imagick floodFillPaintImage() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- PHP | GmagickPixel setcolor() function
- PHP | opendir() Function
- PHP | cal_to_jd() Function
- PHP | stream_get_transports() Function
- PHP | Ds\Deque pop() Function
- PHP | SimpleXMLElement children() Function
- PHP | array_intersect_ukey() Function
- PHP | is_numeric() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

