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

 Check divisibility (Posted on 2015-09-16)
Find all prime numbers p for which number p^2 +11 has exactly six distinct divisors (counting 1 and itself).

 See The Solution Submitted by Ady TZIDON No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
 computer exploration (probable spoiler) | Comment 1 of 5
It seems that p = 3 is the only one that works.

The program finds no other through p almost one million.

DefDbl A-Z
Dim  crlf\$, fct(20, 1)

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

Do
DoEvents
p = nxtprm(p)
v = p * p + 11
f = factor(v): dvsrs = 1
For i = 1 To f
dvsrs = dvsrs * (fct(i, 1) + 1)
Next i
If dvsrs = 6 Then
Text1.Text = Text1.Text & p & Str(v) & crlf
DoEvents
End If
Loop

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
n = n + 1
Wend
nxtprm = n
End Function

Function factor(num)
diffCt = 0: good = 1
nm1 = Abs(num): If nm1 > 0 Then limit = Sqr(nm1) 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
If INKEY\$ = Chr\$(27) Then s\$ = Chr\$(27): Exit Function
Loop
If nm1 > 1 Then diffCt = diffCt + 1: fct(diffCt, 0) = nm1: fct(diffCt, 1) = 1
factor = diffCt
Exit Function

DivideIt:
cnt = 0
Do
q = Int(nm1 / dv)
If q * dv = nm1 And nm1 > 0 Then
nm1 = q: cnt = cnt + 1: If nm1 > 0 Then limit = Sqr(nm1) Else limit = 0
If limit <> Int(limit) Then limit = Int(limit + 1)
Else
Exit Do
End If
Loop
If cnt > 0 Then
diffCt = diffCt + 1
fct(diffCt, 0) = dv
fct(diffCt, 1) = cnt
End If
Return
End Function

Edited on September 17, 2015, 7:46 am
 Posted by Charlie on 2015-09-16 16:13:12

 Search: Search body:
Forums (0)