Cubic-free numbers II

Time Limit: 10000ms
Memory Limit: 131072KB

This problem will be judged on HUST. Original ID: 1214
64-bit integer IO format: %lld      Java class name: Main

 

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;
const int maxn = ;
typedef long long LL;
LL cnt[maxn],L,R;
LL calc(LL x) {
if(x <= ) return ;
memset(cnt,,sizeof cnt);
LL i = ;
for(i = ; i*i*i <= x; ++i)
cnt[i] = x/(i*i*i);
for(LL j = i - ; j >= ; --j) {
for(LL k = j + j; k < i; k += j)
cnt[j] -= cnt[k];
}
LL ret = ;
for(LL j = ; j < i; ++j)
ret += cnt[j];
return ret;
}
int main() {
int kase;
scanf("%d",&kase);
while(kase--) {
scanf("%lld%lld",&L,&R);
printf("%lld\n",R - L - calc(R - ) + calc(L - ));
}
return ;
}

最新文章

  1. 类别(Category)与扩展(Extensions)
  2. deployment与Web应用程序部署
  3. IOS开发基础知识--碎片3
  4. html iframe 元素之间的调用
  5. BI跟报表一样吗?
  6. [C++]C++类基本语法
  7. oracle 之 COMMENT
  8. sass颜色
  9. unity3D学习序幕
  10. Spring+Redis(keyspace notification)实现定时任务(订单过期自动关闭)
  11. Algorithm --&gt; 阶乘和因子
  12. 深入理解Linux内存分配
  13. spring-boot-2.0.3应用篇 - shiro集成
  14. squid代理http和https方式上网的操作记录
  15. 装饰者模式的学习(c#)
  16. ElasticSearch 2 (31) - 信息聚合系列之时间处理
  17. [Winform]关闭窗口使其最小化
  18. uva10905
  19. grep -v grep
  20. spring中的监视器,过滤器,拦截器

热门文章

  1. JavaSwing输入对话框,点击取消抛出异常的解决方法
  2. 为什么JavaWeb项目要分层
  3. [Swift通天遁地]一、超级工具-(17)自定义的CVCalendar日历
  4. robotframework - 框架做接口自动化get请求
  5. Java多线程(二) synchronized 针对对象进行锁定
  6. uiautomatorviewer详解
  7. VB.NET 小程序 4
  8. Android中出现Error:In (declare-styleable) FontFamilyFont, unable to find attribute android:font
  9. re.S解析
  10. Maven对不同的测试环境用不同的参数进行打包