Codeforces Round #471 (Div. 2) C. Sad powers
首先可以前缀和 ans = solve(R) - solve(L-1)
对于solve(x) 1-x当中符合条件的数
分两种情况
- 3,5,7,9次方的数,注意这地方不能含有平方次
- 平方数
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
std::vector<long long> oddNumber;
bool isSqaure(long long x) {
long long t1 = sqrt(x);
return t1 * t1 == x;
}
void pre() {
// get the a^p (p = 3,5,7,9)
oddNumber.clear();
for (long long i = 2; i < 1000001; ++i) {
if (!isSqaure(i)) {
long long initNumber = i * i * i;
long long multiplyNumber = i * i;
oddNumber.push_back(initNumber);
while (1.0 * initNumber * multiplyNumber <= 1e18) {
initNumber *= multiplyNumber;
oddNumber.push_back(initNumber);
}
}
}
sort(oddNumber.begin(), oddNumber.end());
oddNumber.erase(unique(oddNumber.begin(), oddNumber.end()), oddNumber.end());
}
long long solve(long long number) {
if (number == 0)
return 0;
long long result = upper_bound(oddNumber.begin(), oddNumber.end(), number) - oddNumber.begin();
result += (long long)sqrt(number);
return result;
}
int main() {
int Q;
pre();
while (~scanf("%d", &Q)) {
for (int i = 0; i < Q; ++i) {
long long L, R;
scanf("%lld %lld", &L, &R);
printf("%lld\n", solve(R) - solve(L - 1));
}
}
return 0;
}
Codeforces Round #471 (Div. 2) C. Sad powers的更多相关文章
- Codeforces Round #471 (Div. 2) F. Heaps(dp)
题意 给定一棵以 \(1\) 号点为根的树.若满足以下条件,则认为节点 \(p\) 处有一个 \(k\) 叉高度为 \(m\) 的堆: 若 \(m = 1\) ,则 \(p\) 本身就是一个 \(k\ ...
- Codeforces Round #471 (Div. 2)B. Not simply beatiful strings
Let's call a string adorable if its letters can be realigned in such a way that they form two conseq ...
- Codeforces Round #471 (Div. 2)A. Feed the cat
After waking up at hh:mm, Andrew realised that he had forgotten to feed his only cat for yet another ...
- Codeforces Round #486 (Div. 3) D. Points and Powers of Two
Codeforces Round #486 (Div. 3) D. Points and Powers of Two 题目连接: http://codeforces.com/group/T0ITBvo ...
- # Codeforces Round #529(Div.3)个人题解
Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
随机推荐
- Shell脚本——cat/EOF输出多行
在某些场合,可能我们需要在脚本中生成一个临时文件,然后把该文件作为最终文件放入目录中.(可参考ntop.spec文件)这样有几个好处,其中之一就是临时文件不是唯一的,可以通过变量赋值,也可根据不同的判 ...
- nodejs之socket.io模块——实现了websocket协议
Nodejs实现websocket的4种方式:socket.io.WebSocket-Node.faye-websocket-node.node-websocket-server,主要使用的是sock ...
- shell脚本 awk工具
awk工具概述awk编程语言/数据处理引擎基于模式匹配检查输入文本,逐行处理并输出通常在shell脚本中,或取指定的数据单独用时,可对文本数据做统计 命令格式格式一:awk [选项] '[条件]{编辑 ...
- Linux基础二
linux命令分类 内部命令:属于shell解释器 外部命令:独立于shell解释器 检查命令类型 type:检查命令字的类型 [root@localhost ~]# type ls ls 是 `ls ...
- Android WebView的缓存方式分析
WebView的缓存可以分为(1)页面缓存和(2)数据缓存. 页面缓存是指当WebView加载一个网页时的html.JS.CSS等页面或者资源数据.这些缓存资源是由于浏览器的行为而产生,开发者只能通过 ...
- R语言︱H2o深度学习的一些R语言实践——H2o包
每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- R语言H2o包的几个应用案例 笔者寄语:受启发 ...
- 【html5】html5离线存储
html5本地存储之离线存储 1.为什么使用离线存储 ①最新的主流的浏览器中都已添加了对HTML5的offline storage功能的支持,HTML5离线存储功能非常强大, 它的作用是:在用户没有与 ...
- Linux显示目前与过去登入系统的用户相关信息
Linux显示目前与过去登入系统的用户相关信息 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ last youhaido pts/0 :0 Sat Jan 2 ...
- 使用jQuery的一些建议
1.尽可能使用id选择器而不是类选择器 例如: //html <p id="chooseId">测试文本</p> //jQuery console.time ...
- 用winscp从本地上传文件到服务器上出现复制文件到远端时错误。
用winscp从本地上传文件到服务器上出现复制文件到远端时错误. 错误码:4 服务器返回的错误消息:write failed 报错如下图所示: 分析过程: 1.刚开始以为是权限不够,后面上网查了一下是 ...