Documentation

# `nextprime`

Next prime number

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

## Syntax

```nextprime(`m`)
```

## Description

`nextprime(m)` returns the smallest prime number larger than or equal to `m`.

If the argument `m` is an integer, then `nextprime` returns the smallest prime number larger than or equal to `m`. A symbolic call of type `"nextprime"` is returned, if the argument is not of type `Type::Numeric`. An error occurs if the argument is a number that is not an integer.

The first prime number is 2.

## Examples

### Example 1

The first prime number is computed:

`nextprime(-13)`
` `

If the argument of `nextprime` is a prime number, this number is returned:

`nextprime(11)`
` `

We compute a large prime:

`nextprime(56475767478567)`
` `

Symbolic arguments lead to a symbolic call:

`nextprime(x)`
` `

## Parameters

 `m`

## Return Values

Prime number or a symbolic call to `nextprime`.

## References

Michael O. Rabin, Probabilistic algorithms, in J. F. Traub, ed., Algorithms and Complexity, Academic Press, New York, 1976, pp. 21-39.

## Algorithms

`nextprime` uses a fast probabilistic prime number test (Miller-Rabin test) to decide if the computed result is a prime number. The result returned by `nextprime` is either a prime number or a strong pseudo-prime for 10 randomly chosen bases.