Test instructions: Find out how many of the 1-n can be represented as m^k. (n<=10^18)
1. If I^b<=n (b>1), then (1~i) can be expressed in the form of m^k.
2. If the i^4<=n,i^4 can be represented by the (i^2) ^2, then the exponent is a prime number to represent all.
3. Because of the 2^60>10^18, it is only necessary to list the primes within 60.
4. If you simply follow the above to 60 primes (17) Each time pow (N,1.0/prime[i]) (I<17);
In this way, less consideration of duplication, such as 4^3 and 8^2, the exponent is a prime number they are 2^6;
So use the repulsion principle.
5, the direct radical will have the precision loss plus EPS = 1e-8 on the line;
#include <cstdio> #include <cstring> #include <iostream> #include <cmath>using namespace std;# Define ll __int64const Double EPS = 1e-8;ll prim[18]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59};ll n,ans;void dfs (ll index,ll len,ll s,ll num) { if (Num==len) { ll temp= (Pow (n*1.0,1.0/s) +eps) -1;//is repeated every time 1^s is calculated, so subtract, and finally add one on the line ans+=temp* (len &1?1:-1); return; } if (index>=17) return; if (s*prim[index]<=60) dfs (index+1,len,s*prim[index],num+1); DFS (index+1,len,s,num);} int main () {while (scanf ("%i64d", &n)!=eof) { ans=0; for (ll i=1;i<=3;i++) Dfs (0,i,1,0); printf ("%i64d\n", ans+1); } return 0;}
Hdu 2204 Eddy ' s hobby repulsion principle