弱的第一发容斥...光看别人题解理解别人思路花了四十分钟- -果然组合数学这块还是太弱了- -
参考了cxlove大神的博客。附上链接:点击打开链接
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
#define ll long long
int ss[30]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59};
ll n,i,ans;
void dfs(int pos,int num,int k)
{
if(k==0)
{
ll tmp=pow(n,1.0/num);
if(pow(tmp,0.0+num)>n) tmp--;//判断越界
tmp--;
if(tmp>0)
ans=ans+((i&1)?1:-1)*tmp;
return ;
}
if(pos>=17) return ;
if(num*ss[pos]<=60)
dfs(pos+1,num*ss[pos],k-1);
dfs(pos+1,num,k);
}
int main()
{
while(scanf("%I64d",&n)!=EOF)
{
ans=0;
for(i=1;i<=3;i++)
dfs(0,1,i);
cout<<ans+1<<endl;
}
return 0;
}