Codeforces 955C Sad powers (数论)
题目链接:Sad powers
题意:给出n个l和r,求出每个给出的[l,r]之间的可以使是另外一个数的k次方的数。(k>=2)
题解:题目给出的数据范围最大是1E18所以如果要直接把所有的从1-1E18的满足条件的数存下来的话一定会超时,但是我们可以注意到1e6^3 = 1e18,所以我们可以先把指数大于3的满足条件的数存下来,指数为2的分开来算(这里要把是别的数平方的数去掉,为了在后面算指数为2的数的时候更方便)。在算指数为2的数的时候要注意不可以用floor(sqrt(x))这种方法来取整,floor之后的数是double精度不够,对于大整数取整时一定要用自己的二分函数去求!
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5+;
const long long INF = 1e18+;
typedef long long ll;
int N,M,T,S;
vector<long long> vec;
void init()
{
vec.clear();
for(long long t = ;t<=1e6;t++){
int x = floor(sqrt(t));
if(x*x == t) continue;
long long tt = t*t*t;
while(tt <= INF){
vec.push_back(tt);
if(INF/tt >= t*t) tt *= t*t;
else break;
}
}
sort(vec.begin(),vec.end());
vec.erase(unique(vec.begin(), vec.end()), vec.end());
}
long long my_sq(long long x){
long long l = , r = 1e9;
while(l<=r){
long long mid = (l+r) / ;
if(mid * mid <= x) l = mid + ;
else r = mid - ;
}
return l;
}
int main()
{
init();
while(cin>>N)
{
long long l , r;
for(int i=;i<N;i++){
scanf("%lld%lld",&l,&r);
int pos1 = lower_bound(vec.begin(),vec.end(),l) - vec.begin();
int pos2 = upper_bound(vec.begin(),vec.end(),r) - vec.begin();
long long ans1 = pos2 - pos1 ;
long long ans2 = my_sq(r) - my_sq(l-);
cout<<ans1+ans2<<endl;
}
}
return ;
}
Codeforces 955C Sad powers (数论)的更多相关文章
- Codeforces 955C Sad powers(数论)
Codeforces 955C Sad powers 题意 q组询问,每次询问给定L,R,求[L,R]区间内有多少个数可以写成ap的形式,其中a>0,p>1,1 ≤ L ≤ R ≤ 1e1 ...
- Codeforces 955C - Sad powers(数论 + 二分)
链接: http://codeforces.com/problemset/problem/955/C 题意: Q次询问(1≤Q≤1e5),每次询问给出两个整数L, R(1≤L≤R≤1e18),求所有符 ...
- codeforce 955c --Sad powers 思路+二分查找
这一题的题意是 定义一个数,该数特点是为a的p次方 (a>0,p>1) 再给你n个询问,每个询问给出一个区间,求区间内该数的数目. 由于给出的询问数极大(10e5) 所以,容易想到应该 ...
- [CodeForces - 1225C]p-binary 【数论】【二进制】
[CodeForces - 1225C]p-binary [数论][二进制] 标签: 题解 codeforces题解 数论 题目描述 Time limit 2000 ms Memory limit 5 ...
- Codeforces Round #471 (Div. 2) C. Sad powers
首先可以前缀和 ans = solve(R) - solve(L-1) 对于solve(x) 1-x当中符合条件的数 分两种情况 3,5,7,9次方的数,注意这地方不能含有平方次 平方数 #inclu ...
- Educational Codeforces Round 15 Powers of Two
Powers of Two 题意: 让求ai+aj=2的x次幂的数有几对,且i < j. 题解: 首先要知道,排完序对答案是没有影响的,比如样例7 1一对,和1 7一对是样的,所以就可以排序之后 ...
- UVA 10622 - Perfect P-th Powers(数论)
UVA 10622 - Perfect P-th Powers 题目链接 题意:求n转化为b^p最大的p值 思路:对n分解质因子,然后取全部质因子个数的gcd就是答案,可是这题有个坑啊.就是输入的能够 ...
- Educational Codeforces Round 15_B. Powers of Two
B. Powers of Two time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces 1045B Space Isaac - 数论 - Hash
题目传送门 传送门I 传送门II 传送门III 题目大意 给定将$\left \{ 0, 1, \dots, m - 1\right \}$分成了不相交的两个非空集合$A$和$B$,给定$A$,问存在 ...
随机推荐
- maven 学习笔记--仓库,聚合和继承,私服搭建
仓库 http://blog.csdn.net/wanghantong/article/details/36427433 聚合和继承 http://www.cnblogs.com/xdp-gacl/p ...
- 如何在linux centos 环境下运行.exe文件
linux是不能运行window下的可执行文件的,必须借助于wine.百度了以下wine如下: Wine (“Wine Is Not an Emulator” 的递归缩写)是一个能够在多种 POS ...
- 【SQL SERVER】语法复习
一.数据类型 截图来源:http://www.w3school.com.cn/sql/sql_datatypes.asp 二.数据表操作 1.创建数据表 USE [Test] GO /****** ...
- Docker容器学习与分享04
Docker容器的基本操作(2) 基于docker分享03的centos容器,接着学习docker容器的基本操作. docker分享03中创建了一个centos镜像,如果想要查看容器的具体信息就要使用 ...
- 如何在SAE搭建属于自己的黑盒xss安全测试平台
Author:雪碧 http://weibo.com/520613815 此篇文章技术含量不高,大牛不喜勿喷,Thx!写这篇文章主要是为了各位小伙伴在SAE搭建XSSING平台的时候少走点弯路(同志们 ...
- [Python2]介绍关于Uiautomator的watcher使用场景及使用方法
[官方的介绍]: Watcher You can register watcher to perform some actions when a selector can not find a mat ...
- [转][solr] - 索引数据删除
删除solr索引数据,使用XML有两种写法: 1) <delete><id>1</id></delete> <commit/> 2) < ...
- ES6中变量解构的用途—遍历Map结构
- VGA、DVI、HDMI、DP 接口介绍及优劣
VGA.DVI.HDMI.DP 接口介绍及优劣 随着日新月异的发展,就目前显卡上面常见的输出接口而言,我们所熟知的有以下几种: VGA.DVI.HDMI和DP (DisplayPort). 这四种 ...
- Shell脚本查询进程存活信息
脚本代码如下: pid=`cat $2` function status_job(){ pcount=`ps -ef |grep $pid |grep -v grep |wc -l` if [ $pc ...