QB / QB64 Discussion Forum      Other Subforums, Links and Downloads
 


  << Previous TopicReturn to Index  

Find the LAST Prime Number

July 3 2014 at 12:42 PM
Al Gore Rhythm  (no login)

 
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   
AuthorReply
lawgin
(no login)

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
(no login)

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
(no login)

mehr modem kein programm

July 11 2014, 3:38 PM 


in memorian der toxik von den vietnam strom problem

mini g~1


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?
ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
der output ist


You needed 0. 1 seconds
to kill all the sheep.

Excellent job!

Press ESCAPE to return to main menu.

ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß

big apple christian



mein kommentar

PRINT "hahaaaaaaaa du f.... kein generierung mit deinen parti keln moeglich"
PRINT " der spinnt der bat schaumt nit seiner uuu das2 von plus und minus dreck
'sub "bus"
liban ...poisoned
in time from to

there some good aplication answer yes or nothing
if you give him a yes or no question

nut that too much
(perhaps has the game in a workversion too
is the background a piece of it ░░









faellt mir ein


 
 Respond to this message   
 
  << Previous TopicReturn to Index  
 Copyright © 1999-2018 Network54. All rights reserved.   Terms of Use   Privacy Statement