04-21-2023, 02:09 AM
Actually, modifying your nthprime program slightly with Double extended to _Float it still returns the 7th prime as 129..
Code: (Select All)
_Define A-Z As _FLOAT
Const Pi = Atn(1) * 4
Dim As Long i
For i = 1 To 7
Print "Number"; i, "Prime"; nprime(i),
Print "Factorial"; factorial(i)
Next
End
Function factorial## (n As Long)
Dim As Long i
Dim As _Float f
If n = 0 Or n = 1 Then
factorial = 1
Exit Function
End If
f = 1
For i = 2 To n
f = f * i
Next
factorial = f
End Function
Function nprime## (n As Long)
Dim As _Float s1, s2, s3
Dim As _Float i, j
s1 = 0
For i = 1 To 2 ^ n
s2 = 0
For j = 1 To i
s3 = Cos(Pi * (factorial(j - 1) + 1) / j)
s2 = s2 + Fix(s3 * s3)
Next
s1 = s1 + Fix(((n / s2) ^ (1 / n)))
Next
nprime = 1 + s1
End Function