Description
Input
Output
Sample Input
10 36 1000000000000000000
Sample Output
4 9 1001003332
#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; }
原文地址:http://blog.csdn.net/zsgg_acm/article/details/40823401