04-20-2023, 05:07 PM
no chance to produce 100 primes with that lame formula unless you use bignum
here are the first 6 primes
here are the first 6 primes
Code: (Select All)
Dim As Long i
For i = 1 To 6
Print i, nprime(i)
Next
Function factorial# (n As Long)
Dim As Long i
Dim As Double 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 Double s1, s2, s3, Pi: Pi = 3.1415926535897932384626433832795#
Dim As Long 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