zoukankan      html  css  js  c++  java
  • hdu 2204 Eddy's爱好 容斥原理

    Eddy's爱好

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

    Problem Description
    Ignatius 喜欢收集蝴蝶标本和邮票,但是Eddy的爱好很特别,他对数字比较感兴趣,他曾经一度沉迷于素数,而现在他对于一些新的特殊数比较有兴趣。
    这些特殊数是这样的:这些数都能表示成M^K,M和K是正整数且K>1。
    正当他再度沉迷的时候,他发现不知道什么时候才能知道这样的数字的数量,因此他又求助于你这位聪明的程序员,请你帮他用程序解决这个问题。
    为了简化,问题是这样的:给你一个正整数N,确定在1到N之间有多少个可以表示成M^K(K>1)的数。
     
    Input
    本题有多组测试数据,每组包含一个整数N,1<=N<=1000000000000000000(10^18).
     
    Output
    对于每组输入,请输出在在1到N之间形式如M^K的数的总数。
    每组输出占一行。
     
    Sample Input
    10 36 1000000000000000000
     
    Sample Output
    4 9 1001003332
     
    Author
    Eddy
    思路:根据指数找个数,由于n^6=(n^2)^3=(n^3)^2;容斥解决
       比如:10以内的二次方;sqrt(10)=3个;注意精度。。。
       涨知识:求根号,pow(n,1.0/m);
    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define mod 1000000007
    #define inf 999999999
    #define pi 4*atan(1)
    //#pragma comment(linker, "/STACK:102400000,102400000")
    ll p[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59},ans;
    ll gcd(ll x,ll y)
    {
        return y==0?x:gcd(y,x%y);
    }
    void dfs(ll lcm,ll pos,ll step,ll x)
    {
        if(lcm>65)
        return;
        if(pos==17)
        {
            if(step==0)
            return;
            ll temp=(ll)pow(x,1.0/lcm+1e-15);
            if(step&1)
            ans+=temp-1;
            else
            ans-=temp-1;
            return;
        }
        dfs(lcm,pos+1,step,x);
        dfs(lcm/gcd(p[pos],lcm)*p[pos],pos+1,step+1,x);
    }
    int main()
    {
        ll x,y,z,i,t;
        while(~scanf("%I64d",&x))
        {
            ans=0;
            dfs(1,0,0,x);
            printf("%I64d
    ",ans+1);
        }
        return 0;
    }
     
  • 相关阅读:
    MQ怎么解决消息堆积的问题
    怎么解决Mysql的超大分页
    微信小程序开发入门 —— 认识微信小程序
    C++中strcpy()函数和strcpy_s()函数的使用及注意事项
    UML免费建模工具
    UML 各种图总结精华
    TIFF 文件格式
    LIBTIFF+VS15+WIN10编译
    LIBTIFF VS2013下编译LIBTIFF4.0.9
    Qt 多线程之QtConcurrent::map(处理序列容器)
  • 原文地址:https://www.cnblogs.com/jhz033/p/5524031.html
Copyright © 2011-2022 走看看