Post Reply 
HP49-50G Willan's formulae to find p(n), the n-th prime number
05-20-2024, 01:15 AM
Post: #9
RE: HP49-50G Willan's formulae to find p(n), the n-th prime number
pi(x) = n ≈ x/ln(x) --> x has size around n*ln(n)

n^2 upper limit is more than enough. (there are more complicated, better one)

Code:
from gmpy2 import *
F = lambda j: (fac(j-1)+1) % j == 0
F = lambda x: 1 if x==1 else is_prime(x)    # equivalent, but faster

def prime(n):
    return 1 + sum(
      floor((n/sum(F(j) for j in range(1,i+1))) ** (1/n))
                        for i in range(1,n*n+1))

p2> for i in range(1,10): print i, prime(i)
...
1 2.0
2 3.0
3 5.0
4 7.0
5 11.0
6 13.0
7 17.0
8 19.0
9 23.0
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP49-50G Willan's formulae to find p(n), the n-th prime number - Albert Chan - 05-20-2024 01:15 AM



User(s) browsing this thread: 1 Guest(s)