All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 A pandigital sum (Posted on 2017-11-21)
The sum of the first N consecutive prime numbers is a zeroless pandigital. Find N and the corresponding 1-9 pandigital.

 No Solution Yet Submitted by Ady TZIDON No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
 computer solution (spoiler) Comment 1 of 1
The first  8971 primes add up to 394521678.
The first 10474 primes add up to 547128369.
The first 10701 primes add up to 572469138.

N could be 8971, 10474 or 10701.

These are the most satisfying in that no digit is repeated.

If repeated digits are allowed, any of the numbers in the first column below could be N.

The first 25 of all the numbers meeting the criteria follow, regardless of repeated digits:

8971   394521678
10474   547128369
10701   572469138
15474   1245769389
16223   1376249548
16243   1379826584
16285   1387352496
16789   1479315682
17027   1523791648
17676   1648579283
17805   1673998254
18706   1857238649
18781   1872935964
19069   1933827546
20185   2179543686
20673   2291765384
21000   2368647159
21026   2374819465
22880   2836453179
23104   2895147163
24400   3246895173
24417   3251649378
24843   3371952846
25146   3458927361
25814   3654827961

Dim crlf\$

Text1.Text = ""
crlf\$ = Chr(13) + Chr(10)
Form1.Visible = True

p = 1
Do
p = nxtprm(p): n = n + 1
DoEvents
tot = tot + p
tots\$ = LTrim(Str(tot))
good = 0
If InStr(tots, "0") = 0 And Len(tots) > 8 Then
d\$ = "123456789"
For i = 1 To Len(tots)
ix = InStr(d, Mid(tots, i, 1))
If ix > 0 Then
d = Left(d, ix - 1) + Mid(d, ix + 1)
If d = "" Then good = 1: Exit For
End If
Next
If good Then
Text1.Text = Text1.Text & n & "   " & tot & crlf
ct = ct + 1
End If
End If
Loop Until ct = 25

End Sub

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-11-21 10:32:45

 Search: Search body:
Forums (0)