Find the smallest prime containing
every non-prime digit.
The smallest is 104869. Listed below are the first 100 meeting the criterion in the text of the puzzle. Those also satisfying the title of the puzzle are marked with an asterisk. 1043869 is the first one that doesn't fit the title as well, as it includes a digit 3.
104869 *
108649 *
140689 *
140869 *
148609 *
164089 *
164809 *
168409 *
184609 *
186049 *
401689 *
406981 *
408169 *
408691 *
409861 *
416089 *
418069 *
460189 *
460891 *
460981 *
468019 *
468109 *
469801 *
480169 *
486091 *
489061 *
498061 *
601849 *
604189 *
604819 *
608941 *
610849 *
618049 *
640891 *
641089 *
648019 *
649081 *
649801 *
681049 *
681409 *
684091 *
684109 *
689041 *
690841 *
694081 *
801469 *
804619 *
806941 *
809461 *
814069 *
814609 *
841069 *
849061 *
849601 *
860941 *
864091 *
864901 *
904681 *
904861 *
906481 *
946081 *
946801 *
948061 *
964081 *
968041 *
980641 *
1014869 *
1016489 *
1016849 *
1018649 *
1041869 *
1043869
1044689 *
1046189 *
1046389
1046849 *
1046897
1047689
1048609 *
1048963
1049681 *
1049683
1049687
1049861 *
1049863
1061849 *
1063849
1064689 *
1064989 *
1067489
1067849
1068149 *
1068409 *
1068439
1068469 *
1068491 *
1068497
1068499 *
1068941 *
1080649 *
...
p = 1
Do
p = nxtprm(p)
s$ = LTrim(Str(p))
good1 = 1: good2 = 1
For i = 1 To 6
If InStr(s, Mid("014689", i, 1)) = 0 Then good1 = 0
Next
For i = 1 To 4
If InStr(s, Mid("2357", i, 1)) > 0 Then good2 = 0
Next
If good1 Then
Text1.Text = Text1.Text & p
If good2 Then Text1.Text = Text1.Text & " *"
Text1.Text = Text1.Text & crlf
ct = ct + 1
End If
DoEvents
Loop Until ct = 100
...
Function prmdiv(num)
Dim n, dv, q
If num = 1 Then prmdiv = 1: Exit Function
n = Abs(num): If n > 0 Then limit = Sqr(n) Else limit = 0
If limit <> Int(limit) Then limit = Int(limit + 1)
dv = 2: GoSub DivideIt
dv = 3: GoSub DivideIt
dv = 5: GoSub DivideIt
dv = 7
Do Until dv > limit
GoSub DivideIt: dv = dv + 4 '11
GoSub DivideIt: dv = dv + 2 '13
GoSub DivideIt: dv = dv + 4 '17
GoSub DivideIt: dv = dv + 2 '19
GoSub DivideIt: dv = dv + 4 '23
GoSub DivideIt: dv = dv + 6 '29
GoSub DivideIt: dv = dv + 2 '31
GoSub DivideIt: dv = dv + 6 '37
Loop
If n > 1 Then prmdiv = n
Exit Function
DivideIt:
Do
q = Int(n / dv)
If q * dv = n And n > 0 Then
prmdiv = dv: Exit Function
Else
Exit Do
End If
Loop
Return
End Function
Function nxtprm(x)
Dim n
n = x + 1
While prmdiv(n) < n Or n < 2
n = n + 1
Wend
nxtprm = n
End Function
|
Posted by Charlie
on 2017-04-25 09:18:01 |