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连试试水的深浅..... ...
随机推荐
- node实现jsonp跨域
1. 搭建node server //引入模块 var http=require("http"); var fs=require("fs");var url = ...
- Ubuntu 11.04安装arm-linux-gcc-4.4.3/arm-none-linux-gnueabi-gcc安装包
准备工具和系统 arm-linux-gcc-4.4.3.tar.gz arm-linux-gcc-4.4.3下载地址: 下载在Linux公社的1号FTP服务器里,下载地址: FTP地址:ftp://w ...
- Jlink 烧写Uboot
第一章 Hi3531_SDK_Vx.x.x.x版本升级操作说明 如果您是首次安装本SDK,请直接参看第2章. 第二章首次安装SDK 1.Hi3531 SDK包位置 在"Hi3531_V100 ...
- Linux下LCD 10分钟自动关屏的问题总结
Linux下的LCD驱动默认10分钟后会自动关闭屏幕,我们可以修改一下代码让其不自动关屏 在有一个 drivers/char/vt.c 文件其中有一个变量(blankinterval)可以设置它来修改 ...
- Windows--常见端口号
windows--常见端口号 此文档仅供参考,相关端口作用以国际标准为准. 端口:0 服务:Reserved 说明:通常用于分析操作系统.这一方法能够工作是因为在一些系统中"0" ...
- IOS开发之XCode学习013:步进器和分栏控件
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 1.定义UIStepper和UISegmente ...
- 版本控制工具--svn和git的使用(一) -----版本控制的好处以及分类
版本控制工具 版本控制VCS(Version Control Systems)是一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统.这个系统可以自动帮我们备份文件的每一次更改,并且可以 ...
- 复制粘贴之插件(jquery.zclip.min.js)需要安装flash
.line{margin-bottom:20px;} /* 复制提示 */ .copy-tips{position:fixed;z-index:999;bottom:50%;left:50%;marg ...
- DirectSound---音效使用
DirectSound以DMO(DirectX Nedua Objects)的方式提供了对原始音频数据的处理,开发者能够通过VC6.0里的Audio Effect DMO Wizard来开发自定义的D ...
- Postgresql基本用法以及优化注意
本篇为之前学习PG数据库一些基本操作使用以及优化注意. 比较运算符 = : <>,!=,<= , <,>=,>: 不能用于null判断; Between: Le ...