zoukankan      html  css  js  c++  java
  • Eddy's爱好(dfs+容斥)

    Eddy's爱好

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2037    Accepted Submission(s): 857

    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

    题解:错了半天。。。。唉,前期各种试,刚开始少考虑了好多素数,,写的果断错,然后就是思路走歪了,竟然想到了多个2或3,自己乘自己的情况。。。最后借助了还是网上的做法。。。3个多小时啊。。。

    代码:

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<algorithm>
     6 #include<set>
     7 #include<map>
     8 #include<vector>
     9 using namespace std;
    10 const double EPS=1e-8;
    11 #define mem(x,y) memset(x,y,sizeof(x))
    12 const int INF=0x3f3f3f3f;
    13 vector<int>p;
    14 typedef long long LL;
    15 const LL MAXN=1e18;
    16 LL N,sum,I;
    17 void getprim(){
    18     int pp[110];
    19     mem(pp,0);
    20     for(int i=2;i<=60;i++){
    21         for(int j=i*i;j<=60;j+=i)
    22         pp[j]=1;
    23     }
    24     for(int i=2;i<=60;i++)if(!pp[i])p.push_back(i);
    25     //for(int i=0;i<p.size();i++)printf("%d ",p[i]);puts("");
    26 }
    27 void rc(int cur,int pos,int k){
    28     if(k==0){
    29         LL tep=pow(N,1.0/cur);
    30         if(pow(tep,0.0+cur)>N)tep--;
    31         tep--;
    32         if(tep>0)sum+=tep*((I&1)?1:-1);//少了括号。。。。。。。。 
    33         return;
    34     }
    35     if(pos>=17)return;
    36     if(cur*p[pos]<=60)rc(cur*p[pos],pos+1,k-1);
    37     rc(cur,pos+1,k);
    38 }
    39 int main(){getprim();
    40     while(~scanf("%I64d",&N)){
    41         sum=0;
    42         for(I=1;I<=3;I++){
    43             rc(1,0,I);
    44         }
    45         printf("%I64d
    ",sum+1);
    46     }
    47     return 0;
    48 }
  • 相关阅读:
    第一个独立开发的游戏 怪斯特:零 已经上线APP STORE!
    Cocos2d 利用继承Draw方法制作可显示三维数据(宠物三维等)的三角形显示面板
    java 实现 多态的 三要素
    mysql 基础语法掌握~ This is just the beginning.
    rem ~~ 你懂了吗?
    两个css之间的切换
    JavaScript高级程序设计(第3版)
    保持底部~~永远在底部
    文字要对齐!!!
    改变this不要怕!!!
  • 原文地址:https://www.cnblogs.com/handsomecui/p/4988479.html
Copyright © 2011-2022 走看看