# Find the LAST Prime Number

July 3 2014 at 12:42 PM

It is easy to see that there are an infinite number of prime numbers, so there is no last prime with respect to the usual ordering 2,3,5,7, &c.

BUT..... We can order the prime numbers in alphabetical order according to their name in English (ignoring spaces and hyphens).

So "three" comes before "twenty-three" which comes before "two".

What is the *last* prime number in alphabetical order?

The names of the powers of ten are:

hundred, thousand, million, billion (10**9), trillion, quadrillion, quintillion, ..., decillion, undecellion, dodecillion, tredecillion, quattordecillion, ... vigintillion (10**63)

So the last prime should be close to two 2 x 10**63. (So you will need arbitrary precision math unless you want to use a list of prime numbers from the Internet).
You can use a probalistic primality test like Fermat's test.

 Respond to this message
lawgin

# Here's most of the answer

July 4 2014, 3:35 PM
 Using the number descriptions that you provided, the highest number alphabetically would be: two vigintillion two undecillion two trillion two thousand two hundred something. Something would be an odd number between 1 and 99 if, indeed, any of these turn out to be prime. Average spacing between primes at N is about equal to ln(N). ln(10^63) = 145 so it does seem quite possible that one of them would be prime.
 Respond to this message
Anonymous

# Yep

July 4 2014, 6:37 PM
 Scheme's bignum facility allows one to get the answer quickly (just run prime? in a loop) given this information. Code for primality test in Scheme: (define (expmod b e m) (cond ((= e 1) b) ((even? e) (remainder ((lambda (x) (* x x)) (expmod b (/ e 2) m)) m)) (else (remainder (* b (expmod b (- e 1) m)) m)))) ;Value: expmod (define (J a n) (cond ((= a 1) 1) ((even? a) (* (J (/ a 2) n) (if (even? (/ (- (* n n) 1) 8)) 1 -1))) (else (* (J (remainder n a) a) (if (even? (/ (* (- a 1) (- n 1)) 4)) 1 -1))))) ;Value: j ;; Solvay-Strassen test (define (prime? n) (define a (+ 2 (random (- n 2)))) (= (expmod a (/ (- n 1) 2) n) (J a n))) ;Value: prime?
 Respond to this message
Anonymous