codeforces 995C
题意:从L到R 找有几个x,使x=a^p(a>0,p>1)
题解:
一开始把所有符合的次方都存到vector,然后MLE
可以看到1e6^3=1e18,所以可以将二次方单独来求,其他次方存到vector中二分写
注意点:
upper_bound()-lower_bound()
vec.erase(unique(vec.begin(), vec.end()), vec.end());
找二次方不用sqrt,精度不够,用二分来查找
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+;
const int maxn=;
vector<ll> vec;
const ll inf=1e18;
ll L,R;
ll find(ll num){
ll left=;ll right=;
while(left<=right){
ll mid=(left+right)>>;
if(mid*mid>=num){
right=mid-;
}else{
left=mid+;
}
}
return right+;
}
inline void init()
{
for(ll i=;i<=;i++){
ll x = floor(sqrt(i));
if(x*x == i) continue;
ll num=i*i*i;
while(){
vec.push_back(num);
if(num<=inf/(i*i)){
num*=(i*i);
}else{
break;
}
}
}
sort(vec.begin(),vec.end());
vec.erase(unique(vec.begin(), vec.end()), vec.end());
}
int main(){
freopen("in.txt","r",stdin);
int q;
scanf("%d",&q);
init();
while(q--){
scanf("%lld%lld",&L,&R);
ll index1=upper_bound(vec.begin(),vec.end(),R)-vec.begin();
ll index2=lower_bound(vec.begin(),vec.end(),L)-vec.begin();
ll ans=index1-index2;
// cout<<ans<<"\n";
// cout<<find(R+1)<<" "<<find(L)<<"\n";
ans+=find(R+)-find(L);
printf("%lld\n",ans);
}
}
codeforces 995C的更多相关文章
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
- CodeForces - 148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- Java 数据持久化系列之池化技术
在上一篇文章<Java 数据持久化系列之JDBC>中,我们了解到使用 JDBC 创建 Connection 可以执行对应的SQL,但是创建 Connection 会消耗很多资源,所以 Ja ...
- Linux中软件安装包的格式
一.Linux常用安装包及安装方法 1.安装包一般有四类: 1)tar包,如software-1.2.3-1.tar.gz.他是使用UNIX系统的打包工具tar打包的. 2)rpm包,如softwar ...
- IdentityServer4身份认证授权入门
一.简介 IdentityServer4 是为ASP.NET Core 系列量身打造的一款基于 OpenID Connect 和 OAuth 2.0 认证框架 特点: 1.认证服务 2.单点登录登出( ...
- SVM(2)-模式识别课堂笔记
三.非线性支持向量机 问题起源:1.对于一些非线性可分的问题,我们希望能通过一个映射问题将特征映射到新的空间中去(可能是更高维的空间),寄希望于在新的空间中样本能够线性可分:2.我们注意到在线性支持向 ...
- c++中多文件的组织
参考书目:visual c++ 入门经典 第七版 Ivor Horton著 第八章 根据书中例子学习使用类的多文件项目. 首先要将类CBox定义成一个连贯的整体,在CBox.H文件中写入相关的类定义, ...
- python人脸识别
需要掌握知识python,opencv和机器学习一类的基础 过一段时间代码上传github,本人菜j一个,虽然是我自己谢的,也有好多不懂,或者我这就是错误方向 链接:https://pan.baidu ...
- LeetCode 18: 4 Sum 寻找4数和
链接 4Sum 难度 Medium 描述 Given an array nums of n integers and an integer target, are there elements a , ...
- PE可执行文件加载器
PE文件加载器 模仿操作系统,加载pe文件到内存中 该项目主要是为了检测pe的学习程度,是否都完全理解了.当然没有完全理解 实现功能的如下: 模仿操作系统,加载pe文件到内存中,然后执行待执行的pe文 ...
- linux 修改系统时间 同步网络时间
一.date命令 date -s time 修改系统时钟时间为time 设置时间和日期 例如:将系统日期设定成2018年6月8日的命令 命令 : "date -s 06/08/2018&q ...
- Python学习--内置函数isinstance()
内置函数isinstance() isinstance() 函数来判断一个对象是否是一个已知的类型,类似 type(). isinstance() 与 type() 区别: type() 不会认为子类 ...