nextprime: Next Prime Number

View source: R/nextprime.R

20. Next prime numberR Documentation

Next Prime Number

Description

The function nextprime computes and returns the smallest prime number that is greater than the given number.

Usage

nextprime(n, iter = 10, test = "MR")

## Default S3 method:
nextprime(n, iter = 10, test = "MR")

## S3 method for class 'numeric'
nextprime(n, iter = 10, test = "MR")

## S3 method for class 'vli'
nextprime(n, iter = 10, test = "MR")

Arguments

n

object of class vli or 32 bits integer

iter

number of iterations for testing whether or not each number is prime; numeric

test

chosen test: "F" for the Fermat Test, "SS" for the Solovay-Strassen Test or "MR" (by default) for the Miller-Rabin Test; character

Details

The number of iterations is configurable to set the desired accuracy. A small number of iterations might cause not finding a prime number.

Value

object of class vli

Author(s)

Javier Leiva Cuadrado

Examples

n <- as.vli("982234568923564")
x <- nextprime(n)
x
is.prime(x)

VeryLargeIntegers documentation built on May 31, 2023, 7:06 p.m.