Channel
Test instructions: Give you a positive integer n to determine how many numbers can be represented as m^k (k>1) between 1 and N.
Idea: We can be n^ (1/p) and know how many numbers the exponent is p.
By observing, it can be found that if a number can be expressed as x^ (k*t), it can be represented as (x^k) ^t. Therefore, the exponent must be a prime number.
The number of exponents can be obtained by enumerating the primes, but duplicates may occur, for example: X^3=y^5, where x=t^5,y=t^3.
Using the principle of tolerance, set a[i] means the exponent is the number of the first prime, then the answer equals one, minus two, plus three.
Because of the 2^60>10^18,2*3*5*7>60, so just enumerate to three
Code:
#include <cstdio>#include<cstring>#include<cmath>#include<vector>#defineEPS 1e-8#defineMAXN 65typedefLong LongLL;using namespacestd;BOOLP[maxn];vector<int>Prime;voidInit () {intI, J; Memset (P,true,sizeof(p)); for(i =2; I <9; i++) { if(P[i]) { for(j = i * i; j < maxn; J + =i) p[j]=false; }} prime.clear (); for(i =2; i < MAXN; i++) { if(P[i]) prime.push_back (i); }}intMain () {LL n, tmp; intI, J, K, ans; Init (); while(~SCANF ("%i64d", &N)) {ans=1; for(i =0; I < (int) Prime.size (); i++) {tmp= (LL) (POW (DoubleN1.0/prime[i]) +EPS); if(TMP = =1) Break; Ans+ = tmp-1; } for(i =0; I < (int) Prime.size (); i++) { for(j = i +1; J < (int) Prime.size (); J + +) {tmp= (LL) (POW (DoubleN1.0/(Prime[i] * prime[j])) +EPS); if(TMP = =1) Break; Ans-= tmp-1; } } for(i =0; I < (int) Prime.size (); i++) for(j = i +1; J < (int) Prime.size (); J + +) for(k = j +1; K < (int) Prime.size (); k++) {tmp= (LL) (POW (Double) N,1.0/(Prime[i] * prime[j] * prime[k])) +EPS); if(TMP = =1) Break; Ans+ = tmp-1; } printf ("%d\n", ans); } return 0;}
View Code
"Tolerance" HDU 2204 Eddy ' s hobby