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 next Q lines contains two integers LR each (1 ≤ L ≤ R ≤ 1018).

Output

Output Q lines — the answers to the queries.

Example
input

Copy
6
1 4
9 9
5 7
12 29
137 591
1 1000000
output
2
1
0
3
17
1111
Note

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的更多相关文章

  1. Codeforces 955C Sad powers (数论)

    题目链接:Sad powers 题意:给出n个l和r,求出每个给出的[l,r]之间的可以使是另外一个数的k次方的数.(k>=2) 题解:题目给出的数据范围最大是1E18所以如果要直接把所有的从1 ...

  2. Codeforces 955C Sad powers(数论)

    Codeforces 955C Sad powers 题意 q组询问,每次询问给定L,R,求[L,R]区间内有多少个数可以写成ap的形式,其中a>0,p>1,1 ≤ L ≤ R ≤ 1e1 ...

  3. Codeforces Round #471 (Div. 2) C. Sad powers

    首先可以前缀和 ans = solve(R) - solve(L-1) 对于solve(x) 1-x当中符合条件的数 分两种情况 3,5,7,9次方的数,注意这地方不能含有平方次 平方数 #inclu ...

  4. codeforce 955c --Sad powers 思路+二分查找

    这一题的题意是   定义一个数,该数特点是为a的p次方 (a>0,p>1) 再给你n个询问,每个询问给出一个区间,求区间内该数的数目. 由于给出的询问数极大(10e5) 所以,容易想到应该 ...

  5. Codeforces 955C - Sad powers(数论 + 二分)

    链接: http://codeforces.com/problemset/problem/955/C 题意: Q次询问(1≤Q≤1e5),每次询问给出两个整数L, R(1≤L≤R≤1e18),求所有符 ...

  6. CF955C Sad powers 题解

    Content 给你 \(q\) 个询问,每次询问 \([l,r]\) 这个区间内满足 \(x=a^p(a>0,p>1)\) 的 \(x\) 的数量. 数据范围:\(1\leqslant ...

  7. CodeForce-955C

    C. Sad powerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutput ...

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

  9. SAD算法在opencv上的实现代码(c++)

    #include <opencv2/opencv.hpp>#include <opencv2/core/core.hpp>#include <opencv2/highgu ...

随机推荐

  1. 前端面试(原生js篇) - DOM

    根据我的面试经历,一般小公司的面试环节,比较关心框架的熟练程度,以及独立开发组件的能力 但大厂通常有五轮以上的面试,而且对 js 基础语法很是看重 于是我总结了一些关于 js 基础的面试对话,有的当时 ...

  2. 转 [PHP] - 性能加速 - 开启Opcache

    原文地址:[PHP] - 性能加速 - 开启Opcache PHP7已经发布了, 作为PHP10年来最大的版本升级, 最大的性能升级, PHP7在多放的测试中都表现出很明显的性能提升  一.开启Opc ...

  3. Expo大作战(六)--expo开发模式,expo中exp命令行工具,expo中如何查看日志log,expo中的调试方式

    简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,将全部来与官网 我猜去全部机翻+个人 ...

  4. Python Django框架笔记(四):数据分页和CSRF跨站点请求伪造

    (一)数据分页  可以参考  https://docs.djangoproject.com/en/2.0/topics/pagination/ 模板:如果只要显示 1.2.3.4.5.6....的话, ...

  5. su、sudo、su - root的区别

    su和sudo的区别 共同点:都是root用户权限: 不同点:su只获得root权限,工作环境不变,还是在切换之前用户的工作环境:sudo是完全获得root的权限和root的工作环境. sudo:表示 ...

  6. 重学C语言---03数据和C

    1.数据的必要性.数据使我们生活中不可缺少的东西,程序也是如次,离不开数据.将文字.图片和单词等输入到算计,将其展现出来或者做一系列操作等. 2.实例程序. /*rhodium.c--用金属铑衡量体重 ...

  7. COCOMOII

    一.COCOMOII是什么 cocomo是 COnstructive COst MOdel(建设性成本估算模型)的缩写.最早是由Dr. Barry Boehm在1981年提出.是一种精确的.易于使用的 ...

  8. SqlServer为字段创建索引

    语法:CREATE [索引类型] INDEX 索引名称ON 表名(列名) 创建索引实例: 聚簇索引 create clustered index index_name on table_name (c ...

  9. .NET笔试题集(四)

    转载于:http://www.cnblogs.com/ForEvErNoME/archive/2012/09/10/2678727.html 1.请你简单的说明数据库建立索引的优缺点 使用索引可以加快 ...

  10. UNIX高级环境编程(12)进程关联(Process Relationships)- 终端登录过程 ,进程组,Session

    在前面的章节我们了解到,进程之间是有关联的: 每个进程都有一个父进程: 子进程退出时,父进程可以感知并且获取子进程的退出状态. 本章我们将了解: 进程组的更多细节: sessions的内容: logi ...