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

Home > Numbers
A prime nonuplet (Posted on 2017-12-27) Difficulty: 2 of 5
p is a 4-digit prime number. p+30 is also prime. There are 9 primes from p to p+30 inclusive. What is p? What are the 9 primes in the nonuplet?

No Solution Yet Submitted by Math Man    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution (spoiler) | Comment 1 of 4
The 9 primes are:

1277 1279 1283 1289 1291 1297 1301 1303 1307 

DefDbl A-Z
Dim crlf$, pr(9)
Function mform$(x, t$)
  a$ = Format$(x, t$)
  If Len(a$) < Len(t$) Then a$ = Space$(Len(t$) - Len(a$)) & a$
  mform$ = a$
End Function

Private Sub Form_Load()
 Text1.Text = ""
 crlf$ = Chr(13) + Chr(10)
 Form1.Visible = True
 
 p = 1000
 Do
   p = nxtprm(p)
   pr(0) = p
   For i = 9 To 1 Step -1
     pr(i) = pr(i - 1)
   Next
   If pr(9) > 0 Then
     If pr(1) - pr(9) <= 30 Then
       For i = 9 To 1 Step -1
         Text1.Text = Text1.Text & pr(i) & " "
       Next
       Text1.Text = Text1.Text & crlf
     End If
   End If
   DoEvents
 Loop Until p > 10030
 
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-12-27 12:47:03
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 (7)
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