HUST1214(50/600)

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);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值