mersenne: Mersenne Numbers

View source: R/mersenne.R

mersenneR Documentation

Mersenne Numbers

Description

Determines whether p is a Mersenne number, that is such that 2^p - 1 is prime.

Usage

mersenne(p)

Arguments

p

prime number, not very large.

Details

Applies the Lucas-Lehmer test on p. Because intermediate numbers will soon get very large, uses ‘gmp’ from the beginning.

Value

Returns TRUE or FALSE, indicating whether p is a Mersenne number or not.

References

https://mathworld.wolfram.com/Lucas-LehmerTest.html

Examples

mersenne(2)

## Not run: 
  P <- Primes(32)
  M <- c()
  for (p in P)
      if (mersenne(p)) M <- c(M, p)
  # Next Mersenne numpers with primes are 521 and 607 (below 1200)
  M                       # 2   3   5    7    13      17  19  31  61  89  107
  gmp::as.bigz(2)^M - 1   # 3   7  31  127  8191  131071  ... 
## End(Not run) 

numbers documentation built on Nov. 23, 2022, 9:06 a.m.