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 ...
随机推荐
- 符号修饰与函数签名、extern “C”(转载)
转自:http://www.cnblogs.com/monotone/archive/2012/11/16/2773772.html 参考资料: <程序员的自我修养>3.5.3以及3.5. ...
- 【WIP_S4】栈
创建: 2018/01/15 更新: 2018/01/24 更改标题 [[WIP_S3]堆] => [[WIP_S4]堆] 继续添加内容 更新: 2018/05/13 更改标题 [[WIP_S ...
- redis简介及常见问题
目录 简介 特点 优点 高性能 高并发 为什么要用 redis 而不用 map/guava 做缓存? redis 和 memcached 的区别 Redis快的原因 为什么redis是单线程 为什么r ...
- 【React Native】React Native项目设计与知识点分享
闲暇之余,写了一个React Native的demo,可以作为大家的入门学习参考. GitHub:https://github.com/xujianfu/ElmApp.git GitHub:https ...
- 《Maven实战》(许晓斌)导读(读书笔记&第二次读后感)
第一章 Maven简介 Maven是构建工具,但同时还是jar包管理工具.项目信息管理工具 与Make.Ant比较,更为先进 第二章 Maven的安装和配置 Windows和Unix上安装都很简单,下 ...
- WCF学习笔记(1)-一个完整的例子
一.开发环境 IDE:VS2013 OS:Win10 IIS:IIS 10 二.开发流程 1.项目结构 2.添加一个WCF程序 3.删除系统自动生成的两个文件IService1.cs和Service1 ...
- MSSQLServer知识点总结:DDL(create,alter,drop,declare)-未完整
一.开发环境 Window10 二.开发工具 SQLServer2012 三.数据库的操作 1.创建 (1)方式一:使用默认的配置信息 create database T_mydb2 (2)方式二:自 ...
- Python 设计模式--策略模式
策略模式(Strategy Pattern) 策略模式是一种与行为相关的设计模式,允许你在运行时根据指定的上下文确定程序的动作.可以在两个类中封装不同的算法,并且在程序运行时确定到底执行哪中策略. 特 ...
- Python之数据聚合与分组运算
Python之数据聚合与分组运算 1. 关系型数据库方便对数据进行连接.过滤.转换和聚合. 2. Hadley Wickham创建了用于表示分组运算术语"split-apply-combin ...
- Flask Web 发送邮件单文件
import os from flask import Flask, render_template, session, redirect, url_for from flask_script imp ...