Juggler_IN
Active Member
- Joined
- Nov 19, 2014
- Messages
- 358
- Office Version
- 2003 or older
- Platform
- Windows
I want to generate prime nonprime series 2, 7, 19, 29, 53, 71, 97, 103, 137, 173, 193, 233, ... from the initial primes 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229.
A “prime nonprime” prime number is a prime number that occupies a prime-numbered position in the list of all non-prime numbers.
The PARI code below ...
... is essentially picking from primes ... 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229
to output 2, , , 7, , , , 19, , 29, , , , , , 53, , , , 71, , , , , 97, , 103, , , , , , 137, , , , , , , 173, , , , 193, , , , , ,
I have coded PrimePi and IsPrime... But I am unable to implement the PARI code in VBA ...
A “prime nonprime” prime number is a prime number that occupies a prime-numbered position in the list of all non-prime numbers.
The PARI code below ...
Rich (BB code):
(PARI) c(n) = {for(k=0, PrimePi(n), IsPrime(n++)&&k--); n};
t(n) = if(n<3, n-1, c(n-2));
vector(50, n, Primes(t(Primes(n))))
... is essentially picking from primes ... 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229
to output 2, , , 7, , , , 19, , 29, , , , , , 53, , , , 71, , , , , 97, , 103, , , , , , 137, , , , , , , 173, , , , 193, , , , , ,
I have coded PrimePi and IsPrime... But I am unable to implement the PARI code in VBA ...
VBA Code:
Function PrimePi(n As Variant) As Integer
Dim i As Integer, j As Integer
Dim IsPrime As Boolean
Dim Count As Integer
Count = 0&
For i = 2& To n
IsPrime = True
For j = 2& To Sqr(i)
If i Mod j = 0& Then
IsPrime = False
Exit For
End If
Next j
If IsPrime Then Count = Count + 1&
Next i
PrimePi = Count
End Function
Function IsPrime(n As Variant) As Boolean
Dim i As Variant
If n < 2 Then IsPrime = False: Exit Function
For i = 2 To Sqr(n)
If n Mod i = 0 Then IsPrime = False: Exit Function
Next i
IsPrime = True
End Function
Rich (BB code):