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

Home > Numbers
Quintuplet of consecutive primes (Posted on 2018-08-11) Difficulty: 3 of 5
Five Consecutive Primes starting from M1 create two palindromic numbers:
M1*M2*...*M5 = Pal1
M1^2+M2^2+...M5^2 =Pal2

Find M1, Pal1 & Pal2.

I know only one solution...

See The Solution Submitted by Ady TZIDON    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution | Comment 1 of 3
DefDbl A-Z
Dim crlf$

Private Sub Form_Load()
 Text1.Text = ""
 crlf$ = Chr(13) + Chr(10)
 Form1.Visible = True
  
  a = 2: b = 3: c = 5: d = 7: e = 11
  prod = a * b * c * d * e
  Do
    If isPalin(prod) Then
      tot = a * a + b * b + c * c + d * d + e * e
      If isPalin(tot) Then
        Text1.Text = Text1.Text & a & Str(b) & Str(c) & Str(d) & Str(e) & "    " & Str(prod) & Str(tot) & crlf
        done = 1
      End If
    End If
    DoEvents
    f = nxtprm(e)
    a = b: b = c: c = d: d = e: e = f
    prod = a * b * c * d * e
  Loop Until prod > 1E+15
  
  Text1.Text = Text1.Text & crlf & a & Str(prod) & " done "
  
End Sub


Function isPalin(n)
 s$ = Format$(n, "###############")
 
 good = 1

 For i = 1 To Len(s$) / 2
   If Mid$(s$, i, 1) <> Mid$(s$, Len(s$) + 1 - i, 1) Then good = 0: Exit For
 Next
 
 isPalin = good
End Function

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


finds

7 11 13 17 19     323323 989

991 1.02906689782902E+15 done 

meaning M1 is 7, Pal1 is 323323 and Pal2 is 989. Checking for further answers stopped at the prime 991 as the product became over 10^15, beyond the reliable accuracy of VB.

  Posted by Charlie on 2018-08-11 13:42:49
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (5)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information