Jenny's phone number is 867-5309, according to the song. Here are some problems about the number 8675309.
1. 8675309 is prime. How many prime phone numbers are there if phone numbers are 7 digits and cannot start with 0?
2. How many prime phone numbers are there if phone numbers are 7 digits and can start with 0?
3. 8675309 is the 582161st prime, and 582161 is prime, too. Therefore, 8675309 is a
superprime. How many superprimes are ≤8675309?
4. 8675311 is prime. Therefore, 8675309 and 8675311 are twin primes. How many twin prime pairs (n, n+2) are there such that n≤8675309?
I could have sworn that when this was in the queue a combined 3 and 4 was asked for also: a count of superprimes that are also the bottom prime of a twin. In any case, I've included that here also.
10 P=1
20 while P<9999999
30 P=nxtprm(P)
40 inc Ct
50 if P>1000000 then inc Ct7d
60 if prmdiv(Ct)=Ct and P<=8675309 then inc Supct
70 if prmdiv(P+2)=P+2 and P<=8675309 then inc Twinct
80 if prmdiv(Ct)=Ct and prmdiv(P+2)=P+2 and P<=8675309 then inc Suptwinct
150 wend
160 print Ct-1,Ct7d-1,Supct,Twinct,Suptwinct
finds
664579 586081 47753 52196 4281
meaning
664579 primes of up to 7 digits (puzzle part 2),
586081 primes with exactly 7 digits (part 1),
47753 superprimes in the given range,
52196 twin prime pairs,
4281 twin prime pairs where the lower number is a superprime.
BTW, adding line
90 if prmdiv(Ct)=Ct and prmdiv(P-2)=P-2 and P<=8675309 then inc Suptwinct2
finds that 4431 superprimes in the range are the upper number in a twin prime pair.
in fact
100 if prmdiv(Ct)=Ct and prmdiv(P-2)=P-2 and prmdiv(P+2)=P+2 and P<=8675309 then inc Suptwinct3
finds that in two cases a superprime was between two other primes. Actually however there's only one such case: 5: it's the 3rd prime and both 2 and 7 are also prime. The code erroneously counted 3, as the 2nd prime (ok), but it counted 1 as being prime, due to the nature of the UBASIC interpreter giveing 1 as the lowest prime factor of 1. This also affects the count of twin prime pairs where the upper number is a superprime, as it would look at 1 (as that would be p-2) also and declare it prime, so that count should be 4430 rather than 4431.
--------------
And, I see from tomarken's comment that the super prime count itself, 47753 above, is also off by 1. I see now that this is the result of 2 being counted, as it is the 1st prime and the software is again counting 1 as prime.
|
Posted by Charlie
on 2014-02-26 17:07:50 |