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

Home > Numbers
Aloof prime (Posted on 2018-07-12) Difficulty: 3 of 5
53 is notable for being the first prime not to be part of a twin or cousin prime pair.
Its two closest primes are 47 and 59, both of which are sexy primes with 53.

The first prime not to be part of a twin, cousin, or sexy prime pair
is /you tell me/.

See The Solution Submitted by Ady TZIDON    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution discussion and solution | Comment 1 of 2
In one sense, 2 is aloof, as no prime is 2, 4 or 6 units away--only an odd number away from any other prime. However, let's assume 2 is excluded, as its inclusion makes the solution trivial. Here's a classification of the primes from 3 onward until we get to 211, which is aloof. The classification given is the closest such classification: for example 19 is twin to 17 and cousin to 23, so it's classified as a twin.

3 twin
5 twin
7 twin
11 twin
13 twin
17 twin
19 twin
23 cousin
29 twin
31 twin
37 cousin
41 twin
43 twin
47 cousin
53 sexy
59 twin
61 twin
67 cousin
71 twin
73 twin
79 cousin
83 cousin
89 sexy
97 cousin
101 twin
103 twin
107 twin
109 twin
113 cousin
127 cousin
131 cousin
137 twin
139 twin
149 twin
151 twin
157 sexy
163 cousin
167 cousin
173 sexy
179 twin
181 twin
191 twin
193 twin
197 twin
199 twin
211 aloof

The next prime after 211 is 223.

DefDbl A-Z
Dim crlf$

Private Sub Form_Load()
 Text1.Text = ""
 crlf$ = Chr(13) + Chr(10)
 Form1.Visible = True
 
 p2 = prm(2): p = 2
 Do
   If isPrime(p2 - 2) Or isPrime(p2 + 2) Then
     Text1.Text = Text1.Text & p2 & " twin" & crlf
   ElseIf isPrime(p2 - 4) Or isPrime(p2 + 4) Then
     Text1.Text = Text1.Text & p2 & " cousin" & crlf
   ElseIf isPrime(p2 - 6) Or isPrime(p2 + 6) Then
     Text1.Text = Text1.Text & p2 & " sexy" & crlf
   Else
     Text1.Text = Text1.Text & p2 & " aloof" & crlf
     aloof = 1
   End If
   p = p + 1
   p2 = prm(p)
   DoEvents
 Loop Until aloof
 
End Sub

Function isPrime(x)
  p = 0
  If x > 1 Then
    If prmdiv(x) = x Then p = 1
  End If
  isPrime = p
End Function


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

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

The following list of the most stringent classification of primes includes the first four aloof primes:

3 twin
5 twin
7 twin
11 twin
13 twin
17 twin
19 twin
23 cousin
29 twin
31 twin
37 cousin
41 twin
43 twin
47 cousin
53 sexy
59 twin
61 twin
67 cousin
71 twin
73 twin
79 cousin
83 cousin
89 sexy
97 cousin
101 twin
103 twin
107 twin
109 twin
113 cousin
127 cousin
131 cousin
137 twin
139 twin
149 twin
151 twin
157 sexy
163 cousin
167 cousin
173 sexy
179 twin
181 twin
191 twin
193 twin
197 twin
199 twin
211 aloof       <---
223 cousin
227 twin
229 twin
233 cousin
239 twin
241 twin
251 sexy
257 sexy
263 sexy
269 twin
271 twin
277 cousin
281 twin
283 twin
293 aloof       <---
307 cousin
311 twin
313 twin
317 cousin
331 sexy
337 sexy
347 twin
349 twin
353 cousin
359 sexy
367 sexy
373 sexy
379 cousin
383 cousin
389 sexy
397 cousin
401 cousin
409 aloof       <---
419 twin
421 twin
431 twin
433 twin
439 cousin
443 cousin
449 sexy
457 cousin
461 twin
463 twin
467 cousin
479 aloof
487 cousin
491 cousin
499 cousin
503 cousin
509 sexy
521 twin
523 twin
541 sexy
547 sexy
557 sexy
563 sexy
569 twin
571 twin
577 sexy
587 sexy
593 sexy
599 twin
601 twin
607 sexy
613 cousin
617 twin
619 twin
631 aloof        <---

next prime is 641


DefDbl A-Z
Dim crlf$
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
 
 p2 = prm(2): p = 2
 Do
   If isPrime(p2 - 2) Or isPrime(p2 + 2) Then
     Text1.Text = Text1.Text & p2 & " twin" & crlf
   ElseIf isPrime(p2 - 4) Or isPrime(p2 + 4) Then
     Text1.Text = Text1.Text & p2 & " cousin" & crlf
   ElseIf isPrime(p2 - 6) Or isPrime(p2 + 6) Then
     Text1.Text = Text1.Text & p2 & " sexy" & crlf
   Else
     Text1.Text = Text1.Text & p2 & " aloof" & crlf
     aloof = 1 + aloof
   End If
   p = p + 1
   p2 = prm(p)
   DoEvents
 Loop Until aloof > 4
 
 Text1.Text = Text1.Text & "next prime is " & p2
 
End Sub

Function isPrime(x)
  p = 0
  If x > 1 Then
    If prmdiv(x) = x Then p = 1
  End If
  isPrime = p
End Function


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
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 2018-07-12 11:06:25
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