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

 Comb(k,2) (Posted on 2018-03-29)
For which k ≥ 3 is k(k-1)/2 (i.e. k choose 2) one more than a power of a prime number?

 No Solution Yet Submitted by Ady TZIDON No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
 solutions through k=1,000,000 | Comment 2 of 4 |
`k  C(k,2)3    3     2^1+14    6     5^1+15   10     3^2+18   28     3^3+1`

from

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

Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr(13) & Chr(10)

For k = 3 To 1000000
v = k * (k - 1) / 2
f = factor(v - 1)
If f = 1 Then
Text1.Text = Text1.Text & k & Str(v) & crlf
End If
Next

Text1.Text = Text1.Text & crlf & " done"

End Sub

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

DivideIt:
cnt = 0
Do
q = Int(n / dv)
If q * dv = n And n > 0 Then
n = q: cnt = cnt + 1: If n > 0 Then limit = Sqr(n) 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

I could have speeded up runtime if I had modified the factor function to stop after finding a second prime factor, but that would have required extra coding time.

 Posted by Charlie on 2018-03-29 10:11:46
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 (1)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

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