A superprime is an integer such that all its left-to-right initial segments are prime (e.g. 7331 whose segments are 7, 73, 733, and 7331, all prime).
There is a largest superprime.
Find it.
Source: USA Computing Olympiad,
Feb 1995.
(In reply to
re: Another method. by Daniel)
list
10 Pr=2:gosub *Addon
20 Pr=3:gosub *Addon
30 Pr=5:gosub *Addon
40 Pr=7:gosub *Addon
50 end
60
70 *Addon
75 local Dig
80 for Dig=3 to 9 step 2
90 Pr=Pr*10+Dig
100 Digs=int(log(Pr)/log(10))+1
105 Good=1
110 for St=0 to Digs-1
120 Tst=Pr-(Pr\(10^(Digs-St)))*10^(Digs-St)
130 if prmdiv(Tst)<>Tst then Good=0
140 next
200 if prmdiv(Pr)=Pr and Good=1 then
210 :print Pr
220 :gosub *Addon
230 if prmdiv(Pr)=0 then print "**":end
240 Pr=Pr\10
250 next Dig
260 return
OK
run
23
37
373
53
73
OK
|
Posted by Charlie
on 2010-10-20 15:18:20 |