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连试试水的深浅..... ...
随机推荐
- mysql字符设置
MySQL字符集设置 mysql>CREATE DATABASE IF NOT EXISTS mydb default charset utf8 COLLATE utf8_general_ci; ...
- linux dhcp搭建及pxe无人值守装机
DHCP动态主机配置协议:由IETF组织制定,用来简化主机ip地址分配管理可以自动分配的入网参数ip地址/子网掩码/广播地址默认网关地址DNS服务器地址 ----------------------- ...
- java.util.zip.ZipException:ZIP file must have at least one entry
1.错误描述 java.util.zip.ZipException:ZIP file must have at least one entry 2.错误原因 由于在导出文件时,要将导出的文件压缩到压缩 ...
- No bean named 'sessionFactory' is defined
1.错误描述 严重:Servlet service() for servlet default threw exception . org.springframework.beans.factory. ...
- java.lang.ArrayIndexOutOfBoundsException
1.错误描述 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at com.you.m ...
- json格式数据整理
一,json的两种数据结构 1.1,对象 对象结构以"{"大括号开始,以"}"大括号结束.中间部分由0或多个以","分隔的"key ...
- POJ 1087 A Plug for UNIX (网络流,最大流)
题面 You are in charge of setting up the press room for the inaugural meeting of the United Nations In ...
- 八年架构师大咖首次揭秘,年薪50W秘籍!
序言 我是土生土长的老北京人,你们肯定觉得我很有钱,为啥呢? 因为觉得我是北京户口,其实你们错了,我的房子是靠我自己买的,父母基本上没帮到我什么,当然,我也不需要吧! 我只想说,作为一名程序员,我很自 ...
- 论文笔记(6):Weakly-and Semi-Supervised Learning of a Deep Convolutional Network for Semantic Image Segmentation
这篇文章的主要贡献点在于: 1.实验证明仅仅利用图像整体的弱标签很难训练出很好的分割模型: 2.可以利用bounding box来进行训练,并且得到了较好的结果,这样可以代替用pixel-level训 ...
- 论文笔记(2):Deep Crisp Boundaries: From Boundaries to Higher-level Tasks
---------------------------------------------------------------------------------------------------- ...