HUST 1214 Cubic-free numbers II
2024-08-30 22:26:47
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 ;
}
最新文章
- 类别(Category)与扩展(Extensions)
- deployment与Web应用程序部署
- IOS开发基础知识--碎片3
- html iframe 元素之间的调用
- BI跟报表一样吗?
- [C++]C++类基本语法
- oracle 之 COMMENT
- sass颜色
- unity3D学习序幕
- Spring+Redis(keyspace notification)实现定时任务(订单过期自动关闭)
- Algorithm -->; 阶乘和因子
- 深入理解Linux内存分配
- spring-boot-2.0.3应用篇 - shiro集成
- squid代理http和https方式上网的操作记录
- 装饰者模式的学习(c#)
- ElasticSearch 2 (31) - 信息聚合系列之时间处理
- [Winform]关闭窗口使其最小化
- uva10905
- grep -v grep
- spring中的监视器,过滤器,拦截器
热门文章
- JavaSwing输入对话框,点击取消抛出异常的解决方法
- 为什么JavaWeb项目要分层
- [Swift通天遁地]一、超级工具-(17)自定义的CVCalendar日历
- robotframework - 框架做接口自动化get请求
- Java多线程(二) synchronized 针对对象进行锁定
- uiautomatorviewer详解
- VB.NET 小程序 4
- Android中出现Error:In (declare-styleable) FontFamilyFont, unable to find attribute android:font
- re.S解析
- Maven对不同的测试环境用不同的参数进行打包