C-Eddy's hobbies
Time limit:1000 ms
Memory limit:32768kb
64bit Io format:% I64d & % i64usubmitstatus
Description
Ignatius like to collect butterfly specimens and stamps, but Eddy has a special hobby. He is interested in numbers. He used to indulge in prime numbers, now he is interested in some new special numbers.
These special numbers can be expressed as m ^ K. M and K are positive integers and K> 1.
Just as he got addicted again, he found that he didn't know when to know the number of such numbers, so he turned to your smart programmer and asked him to help him solve the problem with the program.
To simplify it, the problem is: give you a positive integer N, and determine the number of numbers between 1 and N that can be expressed as m ^ K (k> 1.
Input
This topic contains multiple groups of test data, each containing an integer of N, 1 <=n <= 1000000000000000000 (10 ^ 18 ).
Output
For each input group, output the total number of input values ranging from 1 to n in the form of M ^ K.
Each group of output occupies one row.
Sample Input
10361000000000000000000
Sample output
491001003332
Concept: the principle of rejection, enumeration index k (k> 1), for each index, you can know the maximum m of m ^ k <= N, And then when k is the sum, you can always convert it to a prime number, so you only need to enumerate the prime number K, but the enumeration process will be repeated. For example, when x ^ 2 = y ^ 3, there are several T (t> 1) so that (t ^ 3) ^ 2 = (t ^ 2) ^ 3 = t ^ 6; here it is easy to think of the principle of rejection, odd addition, even subtraction; the next step is the process of solving the maximum number of M for each K. If the data is too large through enumeration, it will time out, so we can subscribe the formula to m <= n ^ (1/K ), this can be solved directly by using the POW function in the cmath library function. However, because the POW parameter is of the floating point type, you need to pay attention to the Accuracy Problem and add the EPS = 1e-8. the result is added to the result because 1 is also consistent;
AC code:
#include <iostream>#include <cstdio>#include <vector>#include <cmath>using namespace std;typedef long long ll;const double eps = 1e-8;vector<int>tmp;bool is_prime(int x){ for(int i = 2; i <= x / i; i++) if(x % i == 0) return false; return true;}int main(){ ll N; while(cin>>N) { ll ans = 0; tmp.clear(); for(int i = 2; i <= 100; i++) { if(!is_prime(i)) continue; if((1LL << i) > N) break; tmp.push_back(i); } int len = tmp.size(); for(int i = 1; i < (1LL << len); i++) { ll mul = 1,tp = 0; for(int j = 0; j < len; j++) { if((i >> j) & 1) { mul *= tmp[j]; tp++; } } ll isGO = (ll)(pow((double)N,1.0 / mul) + eps) - 1; if(tp & 1) ans += isGO; else ans -= isGO; } cout<<ans + 1<<endl; } return 0;}
C-Eddy's hobbies