HUST 1214 Cubic-free numbers II
Cubic-free numbers II
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的更多相关文章
- LeetCode 445 Add Two Numbers II
445-Add Two Numbers II You are given two linked lists representing two non-negative numbers. The mos ...
- [LeetCode] 445. Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- LeetCode 445. 两数相加 II(Add Two Numbers II)
445. 两数相加 II 445. Add Two Numbers II 题目描述 给定两个非空链表来代表两个非负整数.数字最高位位于链表开始位置.它们的每个节点只存储单个数字.将这两数相加会返回一个 ...
- 445. Add Two Numbers II - LeetCode
Question 445. Add Two Numbers II Solution 题目大意:两个列表相加 思路:构造两个栈,两个列表的数依次入栈,再出栈的时候计算其和作为返回链表的一个节点 Java ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- LeetCode Add Two Numbers II
原题链接在这里:https://leetcode.com/problems/add-two-numbers-ii/ 题目: You are given two linked lists represe ...
- 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 ...
- Lintcode221 Add Two Numbers II solution 题解
[题目描述] You have two numbers represented by a linked list, where each node contains a single digit. T ...
- [Swift]LeetCode445. 两数相加 II | Add Two Numbers II
You are given two non-empty linked lists representing two non-negative integers. The most significan ...
随机推荐
- 使用 script 的 module 属性实现 es6 以上的兼容
几个月前看到了这篇文章 https://philipwalton.com/articles/deploying-es2015-code-in-production-today/,给了我很大的启发,本来 ...
- 【js】再谈移动端的模态框实现
移动端模态框的机制因为与PC的模态框机制一直有所区别,一直是许多新人很容易踩坑的地方,最近笔者作为一条老咸鱼也踩进了一个新坑中,真是平日里代码读得太粗略,故而写上几笔,以儆效尤. 故事的起因是这样的, ...
- Python 设计模式--策略模式
策略模式(Strategy Pattern) 策略模式是一种与行为相关的设计模式,允许你在运行时根据指定的上下文确定程序的动作.可以在两个类中封装不同的算法,并且在程序运行时确定到底执行哪中策略. 特 ...
- [ CERC 2014 ] Vocabulary
\(\\\) \(Description\) 给出三个长度分别为 \(lenA,lenB,lenC\) 的三个字符串 \(A,B,C\) ,其中字符集只包括所有小写字母以及 \(?\) 号. 现在将所 ...
- 使用纯css鼠标移入效果,炫酷的旋转正方体
首先我们需要创建几个盒子 </div> <div class="wrap"> <div class="cube"> < ...
- 全志A33平台编译linux(分色排版)V1.1
全志A33平台编译linux 大文实验室/大文哥 壹捌陆捌零陆捌捌陆捌贰 21504965 AT qq.com 完成时间:2017/12/13 10:41 版本:V1.1 (一)解压缩lichee备用 ...
- python自动化--语言基础四模块、文件读写、异常
模块1.什么是模块?可以理解为一个py文件其实就是一个模块.比如xiami.py就是一个模块,想引入使用就在代码里写import xiami即可2.模块首先从当前目录查询,如果没有再按path顺序逐一 ...
- 【DVWA】【SQL Injection】SQL注入 Low Medium High Impossible
1.初级篇 low.php 先看源码,取得的参数直接放到sql语句中执行 if( isset( $_REQUEST[ 'Submit' ] ) ) { // Get input $id = $_REQ ...
- (转)Hibernate框架基础——映射主键属性
http://blog.csdn.net/yerenyuan_pku/article/details/52740744 本文我们学习映射文件中的主键属性,废话不多说,直接开干. 我们首先在cn.itc ...
- CAD得到指定条件的实体
主要用到函数说明: IMxDrawSelectionSet::Select2 构造选择集.详细说明如下: 参数 说明 [in] MCAD_McSelect Mode 构造选择集方式 [in] VARI ...