nefu 117 素数定理

小明是一个聪明的孩子,对数论有着很浓烈的兴趣。他发现求1到正整数10n 之间有多少个素数是一个很难的问题,该问题的难以决定于n 值的大小。现在的问题是,告诉你n的值,让你帮助小明计算小于10n的素数的个数值共有多少位?

Input

输入数据有若干组,每组数据包含1个整数n(1 < n < 1000000000),若遇到EOF则处理结束。

Output

对应每组数据,将小于10n 的素数的个数值的位数在一行内输出,格式见样本输出。同组数据的输出,其每个尾数之间空一格,行末没有空格。

Sample Input

3
7

Sample Output

3
6

素数定理: 设小于正实数x的素数的个数记为f(x),那么随着x的增长f(x)/(x/log(x)) = 1;

推论:令pn是第n个素数,那么pn ~ nlog(n);

一个数的位数公式:log10(x) + 1;

#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 1000000001
#define ll __int64
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int MAXN = 50010;
int n;
int main()
{
    while(cin >>n){
        cout<<(int)(n - log10(n*1.0) - log10(log(10.0))) + 1<<endl;
    }
    return 0;
}

 

posted @ 2016-04-09 23:13  sweat123  阅读(162)  评论(0编辑  收藏  举报