A positive integer n is called cubic-free, if it can’t be written in this form n = x*x*x*k, while x is a positive integer larger than 1. Now give you two Integers L and R, you should tell me how many cubic-free numbers are there in the range [L, R). Range [L, R) means all the integers x that L <= x < R.
Input
The first line is an integer T (T <= 100) means the number of the test cases. The following T lines are the test cases, for each line there are two integers L and R (L <= R <= ).
Output
For each test case, output one single integer on one line, the number of the cubic-free numbers in the range [L, R).
Sample Input
3
1 10
3 16
20 100
Sample Output
8
12
67
各种很奇怪的优化反正肯定是卡常了
题目很简单
就是素数加上去掉合数
很简单的容斥
#include<bits/stdc++.h>
using namespace std;
#define int long long
int T,n,m;
bool tt[3000001];
int sus[600000];
int dfs(int mulu,int beic,int chus,int susu)
{
if(mulu>susu)return 0;
int daan=0;
for(int a=mulu;a<=susu;a++)
{
if(sus[a]>beic/chus)break;
daan+=beic/(chus*sus[a])-dfs(a+1,beic,chus*sus[a],susu);
}
return daan;
}
int qiu(int w)
{
int daan=0;
int susu=0;
int z=1,y=sus[0];
for(int a=1;a<=sus[0];a++)
{
if(sus[a]>w)break;
susu=max(susu,a);
}
for(int a=1;a<=susu;a++)
{
daan+=w/(sus[a])-dfs(a+1,w,sus[a],susu);
}
return w-daan;
}
main()
{
tt[0]=tt[1]=1;
for(int a=2;a*a<= 3000000;a++)
{
if(tt[a])continue;
for(int b=a+a;b<=3000000;b+=a)
{
tt[b]=1;
}
}
for(int a=1;a<=3000000;a++)
{
if(tt[a])continue;
sus[++sus[0]]=a*a*a*1ll;
}
cin>>T;
while(T--)
{
scanf("%lld%lld",&n,&m);
int tt=qiu(m-1),yy=qiu(n-1);
printf("%lld\n",tt-yy);
}
}