0

I want to identify very large prime number using R software,

> options(max.print=10^9 )
> isPrime(768969862856745523)
Error: cannot allocate vector of size 3.3 Gb

But I didn't get the above number itself... Please try to help me solve the problem

aarthi
  • 85
  • 5

1 Answers1

1
library(gmp)    
x <- as.bigz("768969862856745523")
isprime(x)
[1] 1

So, x is probably prime. You can verify by using my all_divisors function defined here

all_divisors(x)

Big Integer ('bigz') object of length 2:
[1] 1                  768969862856745523
Community
  • 1
  • 1
gd047
  • 29,749
  • 18
  • 107
  • 146
  • I know that the below number was 50 digit prime number but If i use the above command x<-as.bigz("22953686867719691230002707821868552601124472329079") then isprime(x) am getting [1] 1 but the answer is wrong. – aarthi Apr 23 '16 at 09:06
  • 1 means "is probably prime". That's why I use all_divisors. (which by the way shows me that your 50 digit number IS prime) – gd047 Apr 23 '16 at 09:25
  • I know that but am expecting 2(surely prime) because I know that number is prime – aarthi Apr 23 '16 at 09:28
  • You are right. `isprime` is not that useful. I would check whether x is prime or not by giving `length(all_divisors(x))==2` – gd047 Apr 23 '16 at 09:53
  • > length(all_divisors(x))==2 Error: could not find function "all_divisors" – aarthi Apr 23 '16 at 10:51
  • aarthi, the reason `isprime` doesn't know for sure is because it uses the Miller-Rabin primality test, which is a probabilistic test with a known, small chance of failure each time (namely 1/4), which `isprime` reduces by running the test multiple times. It gives you a reasonably certain result without having to spend a ton of time like with a deterministic test. I highly recommend reading the Wikipedia page on Miller-Rabin for further details. It is pretty easy to understand, even for somebody without an advanced math degree like me. – dasf Jun 23 '18 at 01:03