"Tolerance" HDU 2204 Eddy ' s hobby

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.