5

Is $31!+1$ a prime number?

Prime numbers can be written as $6n+1$ or $6n-1$ form.

$31!+1$ can also be written as $6n+1$,but not every number of the form $6n+1$ is prime.

How do I proceed efficiently?

lulu
  • 70,402
mac07
  • 165
  • 4
    That one happens to be divisible by $257$. If your number has a small prime factor then trial and error can find it. Otherwise...well Primality Testing is a very complicated topic. – lulu Aug 16 '16 at 16:22
  • 4
    Note: the remark about $6n\pm 1$ isn't terribly relevant. All that means is that your number is not divisible by $2$ or $3$. Worth checking, of course, but there are lots of other primes to test. – lulu Aug 16 '16 at 16:26
  • 2
    For candidates as small as $31!+1, especially when it has a nice simple expression, you look them up in FactorDB. – hmakholm left over Monica Aug 16 '16 at 16:37
  • @lulu you've linked to a page about critical points. Intentional? – xrisk Aug 16 '16 at 16:39
  • 31! + 1 is not divisible by any prime less than or equal to 31. But that's not enough. Not any reason to believe it isn't divisible by a prime higher than 31. You're kind of stuck. We know 31! = $M10^7$ for some integer $M$ and $M = 3^147^411^213^217192329312^19$ which... doesn't help us at at all really. – fleablood Aug 16 '16 at 16:41
  • @lulu Do I have to know/undersatnd this topic well to solve my problem? – mac07 Aug 16 '16 at 16:42
  • 1
    Well, if you're okay with using Wolfram|Alpha: https://www.wolframalpha.com/input/?i=factors+of+31!+%2B+1 – auden Aug 16 '16 at 16:44
  • @Heather,@henning that's helpful ☺ – mac07 Aug 16 '16 at 16:50
  • @Rishav My mistake, thanks for catching it. Meant to link to Primality Testing – lulu Aug 16 '16 at 16:59
  • Your number is not all that large...only $34$ digits. I just asked Wolfram Alpha, but it would not have been hard to write code to test for small factors. Of course, it gets a lot harder when your number is a lot larger, and when it's factors are also extremely large. – lulu Aug 16 '16 at 17:02

3 Answers3

2

The simplest test is to start with trial division by small primes. Your statement that it is $6n+1$ represents trial division by $2$ and $3$. You can keep going until you get tired. Then try Fermat's little theorem, which says that for $p$ prime and $a$ coprime to $p$, $a^{p-1} \equiv 1 \pmod p$, so see if $2^{8222838654177922817725562880000000} \equiv 1 \pmod {8222838654177922817725562880000001}$ You can do this rather quickly by computer if you have the right package. If this equivalence fails, you have a composite. If it passes, check a few other small primes. If it passes them all, you almost certainly have a prime.

Ross Millikan
  • 374,822
1

Well, first, you can narrow it down a tad.

$31! + 1 = 8222838654177922817725562880000001$

Then, you only need to check numbers up to the square root of the number, because if you have one factor larger than the square root, the other will be smaller.

$\sqrt{8222838654177922817725562880000001} = 90679869067935485.290072114674109180313966488379724733$

which if you round is $90679869067935485$.

Which is also a really large number. Then of course, you only need to check prime factors of number (aka, you can check 5, but you don't need to check 100). And then, after that?

Plug and chug is one way you can go, or you can plug it in to Wolfram|Alpha if you're okay with that. There are also primality tests (I'll be updating this answer with more information).

Finally, below is given some python code that checks if a number is prime (don't plug in $31! + 1$, but the solution to that):

# Python program to check if the input number is prime or not

# take input from the user
num = int(input("Enter a number: "))

# prime numbers are greater than 1
if num > 1:
   # check for factors
   for i in range(2,num):
       if (num % i) == 0:
           print(num,"is not a prime number")
           print(i,"times",num//i,"is",num)
           break
   else:
       print(num,"is a prime number")

# if input number is less than
# or equal to 1, it is not prime
else:
   print(num,"is not a prime number")

Of course, 31! + 1 is not prime; it is divisible by 257, among other numbers.

Hope this helps!

auden
  • 1,774
  • 1
    "Plug and chug is really the only way you can go" - not really. Primality testing can be done in polynomial time, rather than the exponential algorithm you've just described. There are also fast probabilistic tests. – Patrick Stevens Aug 16 '16 at 17:32
  • 1
    @PatrickStevens, my apologies; I'll update my answer. Thank you! – auden Aug 16 '16 at 17:36
1

You can use AKS primality test, which runs in polynomial time.

It has you check if the number is a power, and other quite simple steps.

Here you can find implementations of this algorithm in various programming languages, just in case you are looking to use it in a program of yours.

  • As written in neon pink on that page, the task is not the AKS test. It is really too bad the task has that name. Note that even when considering the real AKS test, there are far faster methods known. – DanaJ Aug 18 '16 at 23:57