HDU 5901 大数素数计数

Count primes


Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1234    Accepted Submission(s): 679




Problem Description
Easy question! Calculate how many primes between [1...n]!
 


Input
Each line contain one integer n(1 <= n <= 1e11).Process to end of file.
 


Output
For each case, output the number of primes in interval [1...n]
 


Sample Input
2
3
10
 


Sample Output
1
2

4




模板题,代码

using namespace std;
#include
#include

const long long N = 5e6 + 2;
bool np[N];
long long prime[N];
long long pi[N];

long long getprime()
{
    long long cnt=0;
    np[0]=np[1]=true;
    pi[0]=pi[1]=0;
    for(long long i=2; ic)
            continue;
        long long lim=suan(sqrt2(w));
        for(long long j=1; j<=lim; j++)
            sum-=suan(w/prime[j])-(j-1);
    }
    return sum;
}
int main()
{
    init();
    long long n;
    while(~scanf("%lld",&n))
        printf("%lld\n",suan(n));
    return 0;
}



你可能感兴趣的:(HDU 5901 大数素数计数)