C. 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))这种方法来取整…
Codeforces 955C Sad powers 题意 q组询问,每次询问给定L,R,求[L,R]区间内有多少个数可以写成ap的形式,其中a>0,p>1,1 ≤ L ≤ R ≤ 1e18. 思路 对于p>2的情况,由于随着指数p的增大,小于1e18的p次幂的数量会急剧减小,总数量的级别在1e6多左右,因此可预处理.L,R不超过1e18,可以直接枚举数字1-1e6,将每个数字不超过1e18的且不是平方数的p次幂推入数组中,排序去重.以便回答询问时可二分求数量. 对于p=2的情况,对上界…
首先可以前缀和 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> oddNumbe…
这一题的题意是   定义一个数,该数特点是为a的p次方 (a>0,p>1) 再给你n个询问,每个询问给出一个区间,求区间内该数的数目. 由于给出的询问数极大(10e5) 所以,容易想到应该打个表来存储这种数.那么问题来了,如果要打1~10e18内a的2次方数的表(即1,4,9,16......)需要从1for循环到1e9,明显也会超时.思考后可以发现,如果从3次方起开始打表的话,复杂度就是从1e6开始,不会超时.所以这题,我们打出3.4.5....次方的表.并且用二分的方式找出区间内二次方的数…
You're given Q queries of the form (L, R). For each query you have to find the number of such x that L ≤ x ≤ R and there exist integer numbers a > 0, p > 1 such that x = ap. Input The first line contains the number of queries Q (1 ≤ Q ≤ 105). The ne…
链接: http://codeforces.com/problemset/problem/955/C 题意: Q次询问(1≤Q≤1e5),每次询问给出两个整数L, R(1≤L≤R≤1e18),求所有符合条件的整数x的个数.条件为:L≤x≤R,x = a的p次方(a, p为整数且a>0, p>1). 分析: 一.当指数p=3时,底数a最多有1e6个,由于指数增加时底数收敛得很快,所以我们可以将p>=3时的所有x放进vector里排序去重(预处理),求x的个数的时候二分查找即可.二.对于p=…
Content 给你 \(q\) 个询问,每次询问 \([l,r]\) 这个区间内满足 \(x=a^p(a>0,p>1)\) 的 \(x\) 的数量. 数据范围:\(1\leqslant q\leqslant 10^5\),\(1\leqslant l\leqslant r\leqslant 10^{18}\). Solution 第一次自己独立做出了紫题,特此发篇题解纪念一下. 首先,我们看到数据范围是 \(10^{18}\) 级别的,看到次幂,然后联想到 \(\sqrt{10^{18}}=…
C. Sad powerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're given Q queries of the form (L, R). For each query you have to find the number of such x that L ≤ x ≤ R and there exist integer…
Don't make a promise when you are in Joy. Don't reply when you are Sad.Don't take decisions when you are Angry.Think Twice.Act Wise. 当你喜悦时,不要轻易地承诺.当你悲伤时,不要轻易地回复.当你愤怒时,不要轻易做出决定.三思而后行,明智之法.…
#include <opencv2/opencv.hpp>#include <opencv2/core/core.hpp>#include <opencv2/highgui/highgui.hpp>#include <iostream>using namespace std;using namespace cv;const int w = 384;const int h = 288;const int n = 3;void SAD(uchar* Limg,…