Main Topic
Find nth prime number, n<=1e9 mess
Drin_e taught me the Chau GE sieve.
But it seems not orthodox.
We can make two points, so we just judge the problem of the number of mass.
Set C[i] denotes the first prime number.
F[i] Indicates the number of the mass of I.
Set g (n,m) to indicate numbers that are not divisible by c[1~m within N.
Set Q=√n, then N of the number of characters f[q]+g (N,f[q])-1 (1 is not prime to subtract)
Apparently G (n,m) =g (n,m-1)-G (n/c[m],m-1)
Pay attention to the boundary m=0 or 1
and metaphysical optimization.
Set MAXN as the pretreatment range
When N<=MAXN
If f[n]<=m, only 1 matches return 1
Otherwise, if f[√n]<=m, return f[n]+1-m (except for prime numbers outside M prime)
See code for details.
Complexity is not proven.
MAXN open to 1e7 almost.
#include <cstdio> #include <algorithm> #include <cmath> #define FO (i,a,b)
for (i=a;i<=b;i++) using namespace std;
typedef long Long LL;
const int MAXN=12500000+10;
ll F[MAXN],C[MAXN];
BOOL BZ[MAXN];
ll I,j,k,t,n,m,q,top;
ll L,r,mid;
ll G (ll n,int m) {if (!m) return n;
if (m==1) return N-N/2;
if (n<=maxn-10) {if (f[n]<=m) return 1;
if (f[(int) sqrt (n)]<=m) return f[n]+1-m;
} return G (N,m-1)-G (n/c[m],m-1);
} ll count (ll N) {Q=floor (sqrt (n));
Return F[q]+g (N,f[q])-1;
} int main () {fo (i,2,maxn-10) {if (!bz[i]) c[++top]=i;
Fo (j,1,top) {if (i*c[j]>maxn-10) break;
Bz[i*c[j]]=1;
if (i%c[j]==0) break;
}} f[1]=0;
Fo (i,2,maxn-10) f[i]=f[i-1]+ (!bz[i]);
scanf ("%d", &n);
l=1;r=22801763489;
while (L<r) {mid= (l+r)/2;
if (count (mid) >=n) R=mid;else l=mid+1;
} printf ("%lld\n", L); }