首先可以前缀和 ans = solve(R) - solve(L-1)

对于solve(x) 1-x当中符合条件的数

分两种情况

  1. 3,5,7,9次方的数,注意这地方不能含有平方次
  2. 平方数
#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的更多相关文章

  1. Codeforces Round #471 (Div. 2) F. Heaps(dp)

    题意 给定一棵以 \(1\) 号点为根的树.若满足以下条件,则认为节点 \(p\) 处有一个 \(k\) 叉高度为 \(m\) 的堆: 若 \(m = 1\) ,则 \(p\) 本身就是一个 \(k\ ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. # Codeforces Round #529(Div.3)个人题解

    Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...

  6. 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 ...

  7. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  8. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

随机推荐

  1. hadoop配置遇到问题的解决

    1. ssh localhost: 不能登陆:将错误提示中的文件全部删除.原因:登陆过远程主机 2. 问题: 伪分布式datanode启动不了:在datanode的log日志文件出现以下错误提示:   ...

  2. hive上mysql元数据库配置

    hive调试信息显示模式: ./hive -hiveconf hive.root.logger=DEBUG,console 非常有用. 默认情况下,Hive元数据保存在内嵌的 Derby 数据库中,只 ...

  3. eclipse web and java ee development

    1.打开Eclipse ->help ->install new software 2.Work with:http://download.eclipse.org/releases/gan ...

  4. 记录一下html渲染页面的 js框架

    1.artTemplate 2.laytpl 3.juicer 4.doT 5.Mustache 6.Handlebars 7.baiduTemplate 8.KissyTemplate 详细的以后补 ...

  5. 关于 frame的一些基本知识

    关于 frame的一些基本知识只是摘抄了一部分,供初学者参考. b.帧速率: 帧速率是每秒显示的图像数.标准影片(NTSC) 是29.97 帧第秒 (fps),电影是每秒24 帧fps.欧洲标准是(P ...

  6. javascript 获取随机数

    javascript 获取随机数 var rand=Math.floor(Math.random()*(n+1)) floor 向下取整 random 获得0-1之间的随机数

  7. Servlet.service() for Servlet jsp threw exception javax.servlet.ServletException:File &quot;/pageFoo

    1.错误描述 Servlet.service() for Servlet jsp threw exception javax.servlet.ServletException:File "/ ...

  8. Linux显示指定区块大小为1048576字节

    Linux显示指定区块大小为1048576字节 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ df -m 文件系统 1M-blocks 已用 可用 已用% 挂 ...

  9. The Eclipse executable launcher was unable to locate its companion launcher jar的解决方法

    大家都知道eclipse是免安装的,基本上解压就能用,但是笔者在解压后打开eclipse时遇到一个奇葩的问题,如题目所示. 在网上搜了半天,基本上都说的是:The Eclipse executable ...

  10. [SDOI2010]粟粟的书架

    题目大意: 网址:https://daniu.luogu.org/problemnew/show/2468 大意:本题有两问: [1] 给定一个\(R*C\)的带权矩阵,询问\(2×10^5\)次在一 ...