The LSD's (least significant digits) of all prime numbers, other than the special cases of primes 2 and 5, come from just four digits: 1, 3, 7, or 9.
Which of these LSD's occurs most frequently amongst primes less than 10000?
DefDbl A-Z
Dim ct(9), crlf$
Private Sub Form_Load()
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
For i = 1 To 10000
p = prm(i)
If p > 10000 Then Exit For
d = p Mod 10
ct(d) = ct(d) + 1
Next
Text1.Text = Text1.Text & i - 1 & Str(prm(i - 1)) & crlf
For j = 1 To 9
Text1.Text = Text1.Text & Str(ct(j))
Next
Text1.Text = Text1.Text & crlf
End Sub
Function prm(i)
Dim p As Long
Open "17-bit primes.bin" For Random As #111 Len = 4
Get #111, i, p
prm = p
Close 111
End Function
reports (with my annotations):
largest prime in range: prime(1229) = 9973
counts by last digit:
1 2 3 4 5 6 7 8 9
306 1 310 0 1 0 308 0 303
The numbers do add up to 1229 as 2 and 5 were included.
|
Posted by Charlie
on 2015-02-08 16:15:06 |