C. Sad powers
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.
The first line contains the number of queries Q (1 ≤ Q ≤ 105).
The next Q lines contains two integers L, R each (1 ≤ L ≤ R ≤ 1018).
Output Q lines — the answers to the queries.
6
1 4
9 9
5 7
12 29
137 591
1 1000000
2
1
0
3
17
1111
In query one the suitable numbers are 1 and 4.
提供一种容斥原理的思想。
我们要求不大于n的所有幂数的个数。
把注意力先放在幂这个东西上
ci=pow(n,(1/i))可以得到所有以i为幂,小于等于n的底数的个数
那么最终答案是否是c1+c2+c3+...+ck呢
不是,因为有重复(例如:c2,c3间2^6这个数是被重复计算过的,但我们发现c2,c3的重复的这些数正好是c6)
进一步分析来看,
两个幂数:
ci,cj(i,j均可分解为奇数个不同质数的乘积)间重复的数为ck(k=lcm(i,j),且k一定可以分解为偶数个不同质数的乘积)
ans=ci+cj-ck
三个幂数:(看图)
ans=ci+cj+ck-c(ij)-c(jk)-c(ik)+c(ijk)
这不就是容斥原理么!!!
所以具体操作上,先打个容斥表
对象是幂
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define inf 2147483647
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define ri register int
template <class T> inline T min(T a, T b, T c)
{
return min(min(a, b), c);
}
template <class T> inline T max(T a, T b, T c)
{
return max(max(a, b), c);
}
template <class T> inline T min(T a, T b, T c, T d)
{
return min(min(a, b), min(c, d));
}
template <class T> inline T max(T a, T b, T c, T d)
{
return max(max(a, b), max(c, d));
}
#define scanf1(x) scanf("%d", &x)
#define scanf2(x, y) scanf("%d%d", &x, &y)
#define scanf3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define scanf4(x, y, z, X) scanf("%d%d%d%d", &x, &y, &z, &X)
#define pi acos(-1)
#define me(x, y) memset(x, y, sizeof(x));
#define For(i, a, b) for (int i = a; i <= b; i++)
#define FFor(i, a, b) for (int i = a; i >= b; i--)
#define bug printf("***********\n");
#define mp make_pair
#define pb push_back
const int maxn = ;
// name*******************************
int a[];
ll l,r,q; // function******************************
ll sol(ll x)
{
ll s=x?:;//大于1就先加上1
for(ll i=; (1ll<<i)<=x; i++)
s-=a[i]*((int)pow((lb)x+0.5,(lb)/i)-);//记得减一,1不能参与计数了
return s;
}
//***************************************
int main()
{
// ios::sync_with_stdio(0);
// cin.tie(0);
// freopen("test.txt", "r", stdin);
// freopen("outout.txt","w",stdout);
a[]=; for(int i=; i<=; i++)
for(int j=i*; j<=; j+=i)
a[j]-=a[i];
cin>>q;
while(q--)
{
cin>>l>>r;
cout<<sol(r)-sol(l-)<<endl;
}
return ;
}
C. Sad powers的更多相关文章
- Codeforces 955C Sad powers (数论)
题目链接:Sad powers 题意:给出n个l和r,求出每个给出的[l,r]之间的可以使是另外一个数的k次方的数.(k>=2) 题解:题目给出的数据范围最大是1E18所以如果要直接把所有的从1 ...
- Codeforces 955C Sad powers(数论)
Codeforces 955C Sad powers 题意 q组询问,每次询问给定L,R,求[L,R]区间内有多少个数可以写成ap的形式,其中a>0,p>1,1 ≤ L ≤ R ≤ 1e1 ...
- Codeforces Round #471 (Div. 2) C. Sad powers
首先可以前缀和 ans = solve(R) - solve(L-1) 对于solve(x) 1-x当中符合条件的数 分两种情况 3,5,7,9次方的数,注意这地方不能含有平方次 平方数 #inclu ...
- codeforce 955c --Sad powers 思路+二分查找
这一题的题意是 定义一个数,该数特点是为a的p次方 (a>0,p>1) 再给你n个询问,每个询问给出一个区间,求区间内该数的数目. 由于给出的询问数极大(10e5) 所以,容易想到应该 ...
- Codeforces 955C - Sad powers(数论 + 二分)
链接: http://codeforces.com/problemset/problem/955/C 题意: Q次询问(1≤Q≤1e5),每次询问给出两个整数L, R(1≤L≤R≤1e18),求所有符 ...
- CF955C Sad powers 题解
Content 给你 \(q\) 个询问,每次询问 \([l,r]\) 这个区间内满足 \(x=a^p(a>0,p>1)\) 的 \(x\) 的数量. 数据范围:\(1\leqslant ...
- CodeForce-955C
C. Sad powerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutput ...
- 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.
Don't make a promise when you are in Joy. Don't reply when you are Sad.Don't take decisions when you ...
- SAD算法在opencv上的实现代码(c++)
#include <opencv2/opencv.hpp>#include <opencv2/core/core.hpp>#include <opencv2/highgu ...
随机推荐
- HDU1045(KB10-A 二分图最大匹配)
Fire Net Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- Hadoop HDFS 的 HttpFS
参考 Hadoop权威指南 第3章中3.4节 背景 要写一个操作HDFS的web后台(文件CRUD),虽然可以直接使用HDFS提供的FileSystem类然后通过get方法获取到一个Distribut ...
- python学习之老男孩python全栈第九期_day009之初始函数初窥
'''# len# 计算字符串的长度# s = '金老板小护士'# len(s)# 不能用 len 怎么办#low一点的方法# count = 0# for i in s:# count += 1# ...
- linux服务器SSH破解预防方法
1.linux服务器通过配置 /etc/hosts.deny 禁止对方IP通过SSH登录我的服务器 vim /etc/hosts.deny 2.不用SSH服务的默认端口22,重新设置一个新端口,最好设 ...
- javascript原型对象与原型链
在javascript中,当系统加载构造函授后 ,会自动在内存中增加一个对象,这个对象就是原型对象.构造函数和原型对象在内存中表现为相互独立,但两者之间还存在联系,构造函数的prototype是原型对 ...
- 第二十七天- 网络通信协议 TCP UDP 缓冲区
1.网络通信协议 osi七层模型:按照分工不同把互联网协议从逻辑上划分了层级 socket层 2.理解socket: Socket是应用层与TCP/IP协议族通信的中间软件抽象层,它是一组接口.在设计 ...
- 使用标准C读取文件遇到的结构体对齐问题及其解决办法
作者:朱金灿 来源:http://blog.csdn.net/clever101 同事使用标准C库读取文件,发现总是读取不对,让我帮忙看一下. 原来他定义了如下一个结构体: // 定义块的结构 typ ...
- readlink 命令
在Linux中readlink命令的作用是:输出符号链接值或权威文件名(通常使用的是-f参数) 格式:readlink [选项]... 文件 参数: -f, --canonicalize 递归跟随 ...
- SLAM产品化的一些思考
这两年一直在做SLAM产品化的一些工作,有些感触,想和大家分享一下.很多想法只是个人浅见,不当之处还望大家指正. 我这两年分别做了AR眼镜和辅助驾驶方向的开发,说实话,挫折大于成果.SLAM产品化之难 ...
- 使用FireFox插件RESTClient、HttpRequester模拟http(get post)请求
我们写好一个接口后,需要进行测试.有时我们会写一个html表单提交,无疑增加了工作量,尤其是当参数比较多或者传json或xml数据时,效率更是大大降低.我们可以使用基于FireFox的RESTClie ...