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 ;
}

HUST 1214 Cubic-free numbers II的更多相关文章

  1. LeetCode 445 Add Two Numbers II

    445-Add Two Numbers II You are given two linked lists representing two non-negative numbers. The mos ...

  2. [LeetCode] 445. Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

  3. LeetCode 445. 两数相加 II(Add Two Numbers II)

    445. 两数相加 II 445. Add Two Numbers II 题目描述 给定两个非空链表来代表两个非负整数.数字最高位位于链表开始位置.它们的每个节点只存储单个数字.将这两数相加会返回一个 ...

  4. 445. Add Two Numbers II - LeetCode

    Question 445. Add Two Numbers II Solution 题目大意:两个列表相加 思路:构造两个栈,两个列表的数依次入栈,再出栈的时候计算其和作为返回链表的一个节点 Java ...

  5. [LeetCode] Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

  6. LeetCode Add Two Numbers II

    原题链接在这里:https://leetcode.com/problems/add-two-numbers-ii/ 题目: You are given two linked lists represe ...

  7. 445. Add Two Numbers II ——while s1 or s2 or carry 题目再简单也要些测试用例

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

  8. Lintcode221 Add Two Numbers II solution 题解

    [题目描述] You have two numbers represented by a linked list, where each node contains a single digit. T ...

  9. [Swift]LeetCode445. 两数相加 II | Add Two Numbers II

    You are given two non-empty linked lists representing two non-negative integers. The most significan ...

随机推荐

  1. Python网咯爬虫 — Scrapy框架应用

    Scrapy框架       Scrapy是一个高级的爬虫框架,它不仅包括了爬虫的特征,还可以方便地将爬虫数据保存到CSV.Json等文件中.       Scrapy用途广泛,可以用于数据挖掘.监测 ...

  2. bzoj1015星球大战(并查集+离线)

    1015: [JSOI2008]星球大战starwar Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 5572  Solved: 2563 Descri ...

  3. 慕课网2-5 编程练习:通过jQuery通配符选择器进行文字变色

    2-5 编程练习 请请使用*选择器将div标签中的字体颜色变成红色 效果图: 任务 (1)使用通配符选择器 (2)使用jQuery的.css()方法设置样式,语法css('属性 '属性值') 参考代码 ...

  4. php insteadof 作用

    PHP5的另一个新成员是instdnceof关键字.使用这个关键字可以确定一个对象是类的实例.类的子类,还是实现了某个特定接口,并进行相应的操作.在某些情况下,我们希望确定某个类是否特定的类型,或者是 ...

  5. loadrunner11 安装破解,汉化包

    说说自己的心痛史,好不容易安装了loadrunner 11 居然浏览器不支持,我的系统是win8.1,ie浏览器最低支持ie11,我还能说啥子...其他浏览器试过了依旧是不可以!!所以我安装了一个虚拟 ...

  6. 用Movie显示gif(1)SimpleGif

    代码如下: import android.content.Context; import android.graphics.Canvas; import android.graphics.Movie; ...

  7. Font Awesome 图标使用总结

    参考 http://fontawesome.dashgame.com/ 1 大图标递进  fa-lg (33%递增).fa-2x. fa-3x.fa-4x,或者 fa-5x  2 固定宽度  fa-f ...

  8. jQuery 遍历 - children() 方法

    jQuery 遍历参考手册 实例 找到类名为 "selected" 的所有 div 的子元素,并将其设置为蓝色: $("div").children(" ...

  9. SpringBoot项目的mybatis逆向工程

    <dependencies> <!--mybatis--> <dependency> <groupId>org.mybatis.spring.boot& ...

  10. 安卓app测试之内存分析

    一.内存分析步骤 1.启动App. 2.使用monitor命令打开:ADM(包含DDMS) ->update heap 3.操作app,点几次GC 4.dump heap 5.hprof-con ...