数的位数计算

原题链接:http://acm.nefu.edu.cn/JudgeOnline/problemshow.php?problem_id=117

分析:设数为N,则其位数为(int)lg(N)+1;log(10)=ln(10);

素数定理:令Pn表示<n的素数个数,则当n较大时有Pn~nln(n).

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<algorithm>
 6 using namespace std;
 7 int main()
 8 {
 9     int n;
10     double e=2.71828;
11     while(cin>>n)
12     {
13         double ans=double(n-log10(n)-log10(log(10)));
14         cout<<(int)ans+1<<endl;
15     }
16     return 0;
17 }
View Code

 

posted @ 2013-09-04 23:39  EtheGreat  阅读(210)  评论(0编辑  收藏  举报