Eddy's爱好 hdu2204

Eddy's爱好

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1266    Accepted Submission(s): 541


Problem Description
Ignatius 喜欢收集蝴蝶标本和邮票,但是Eddy的爱好很特别,他对数字比较感兴趣,他曾经一度沉迷于素数,而现在他对于一些新的特殊数比较有兴趣。
这些特殊数是这样的:这些数都能表示成M^K,M和K是正整数且K>1。
正当他再度沉迷的时候,他发现不知道什么时候才能知道这样的数字的数量,因此他又求助于你这位聪明的程序员,请你帮他用程序解决这个问题。
为了简化,问题是这样的:给你一个正整数N,确定在1到N之间有多少个可以表示成M^K(K>1)的数。
 
Input
本题有多组测试数据,每组包含一个整数N,1<=N<=1000000000000000000(10^18).
 
Output
对于每组输入,请输出在在1到N之间形式如M^K的数的总数。
每组输出占一行。
 
Sample Input
10 36 1000000000000000000
 
Sample Output
4 9 1001003332
 
 1 #include <iostream>
 2 #include <string.h>
 3 #include <stdio.h>
 4 #include <math.h>
 5 using namespace std;
 6 int a[]= {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59};
 7 int b[]= {6,10,14,15,21,22,26,33,34,35,38,39,46,51,55,57,58};
 8 long long n,an;
 9 void dfs()
10 {
11     int i;
12     for(i=0; i<17; i++)
13     {
14         long long h=pow(n,1.0/a[i]);
15         if(pow(h+1,a[i])<=n)h++;
16         if(h<2)break;
17         an+=h-1;
18     }
19     for(i=0; i<17; i++)
20     {
21         long long h=pow(n,1.0/b[i]);
22         if(pow(h+1,b[i])<=n)h++;
23         if(h<2)break;
24         an-=h-1;
25     }
26     if(n-pow(2.0,30)>=0) an++;
27     if(n-pow(2.0,42)>=0) an++;
28     if(n-pow(3.0,30)>=0) an++;
29     an++;
30 }
31 int main()
32 {
33     while(cin>>n)
34     {
35         an=0;
36         dfs();
37         cout<<an<<endl;
38     }
39 }
View Code
原文地址:https://www.cnblogs.com/ERKE/p/3631436.html