Hdu 2204 Eddy ' s hobby repulsion principle

Source: Internet
Author: User

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

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.