The gmp_nextprime() is an inbuilt function in PHP which is used to calculate the prime number just greater than a given GMP number(GNU Multiple Precision : For large numbers).
Syntax:
gmp_nextprime($num)
Parameters: This function accepts a GMP number $num as a mandatory parameter as shown in the above syntax whose next prime we want to find. This parameter can be a GMP object in PHP version 5.6 and later, or we are also allowed to pass a numeric string provided that it is possible to convert that string to a number.
Return Value: This function returns a GMP number which is the prime number just greater than the GMP number passed to it as a parameter.
Examples:
Input : gmp_nextprime("15")
Output : 17
Input : gmp_nextprime("21")
Output : 23
Below programs illustrate the gmp_nextprime() function in PHP :
Program 1: Program to calculate the prime number just greater than a GMP number when numeric string as GMP number is passed as an argument.
<?php // PHP program to calculate the prime number greater // than that of a GMP number passed as arguments // strings as GMP numbers $num = "135"; // gives the prime number just greater // than 135 as a GMP number $res = gmp_nextprime($num); echo $res; ?> |
Output:
137
Program 2: Program to calculate the prime number greater than that of a GMP number when GMP number is passed as an argument.
<?php // PHP program to calculate the prime // number greater than that of a GMP number // creating GMP numbers using gmp_init() $num = gmp_init(1000); // gives the prime number just greater // than 1000 as a GMP number $res = gmp_nextprime($num); echo $res; ?> |
Output:
1009
Reference:
http://php.net/manual/en/function.gmp-nextprime.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.

