Description

Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more and more interesting things about GCD. Today He comes up with Range Greatest Common Divisor Query (RGCDQ). What’s RGCDQ? Please let me explain it to you gradually. For a positive integer x, F(x) indicates the number of kind of prime factor of x. For example F(2)=1. F(10)=2, because 10=2*5. F(12)=2, because 12=2*2*3, there are two kinds of prime factor. For each query, we will get an interval [L, R], Hdu wants to know maxGCD(F(i),F(j)) (L≤i<j≤R)
 

Input

There are multiple queries. In the first line of the input file there is an integer T indicates the number of queries. 
In the next T lines, each line contains L, R which is mentioned above.

All input items are integers. 
1<= T <= 1000000 
2<=L < R<=1000000 

 

Output

For each query,output the answer in a single line. 
See the sample for more details. 
 

Sample Input

2
2 3
3 5
 

Sample Output

1
1
 
注意到F值不大。直接用筛法预处理出F值。用数组num[i][j]记录前 i 个数中有多少个 j。
然后暴力。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define maxn 1000005
int t,l,r,F[maxn],num[maxn][],cnt[],ans;
void init(){
for(int i=;i<=;i++){
if(F[i]==){
for(int j=i<<;j<=;j+=i)
F[j]++;
F[i]=;
}
}
for(int i=;i<=;i++){
for(int j=;j<=;j++){
num[i][j]=num[i-][j];
if(F[i]==j) num[i][j]++;
}
}
}
int main(){
init();
scanf("%d",&t);
while(t--){
ans=;
scanf("%d%d",&l,&r);
for(int i=;i<=;i++){
cnt[i]=num[r][i]-num[l-][i];
if(cnt[i]>) ans=i;
}
if(cnt[]&&cnt[]) ans=max(ans,);
if(cnt[]&&cnt[]) ans=max(ans,);
if(cnt[]&&cnt[]) ans=max(ans,);
if(cnt[]&&cnt[]) ans=max(ans,);
printf("%d\n",ans);
}
return ;
}
 
 
 
 
 

2015 多校赛 第三场 1002 (hdu 5317)的更多相关文章

  1. 2015 多校赛 第五场 1010 (hdu 5352)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5352 看题看得心好累. 题目大意: 给出 n 个点,依次执行 m 次操作:输入“1 x”时,表示将与 ...

  2. 2015 多校赛 第七场 1011 (hdu 5379)

    题意:给定一棵树,树上有 n 个节点.问有多少种方案,使得在每个节点上依次放置数 1~n 后,每个节点的儿子节点上的数连续(比如 1 为根,有1-2,1-3,1-4,则令2,3,4上的数连续),每个子 ...

  3. 2015 多校赛 第五场 1006 (hdu 5348)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5348 题目大意:给出一幅无向图,问是否存在一种方案,使得给每条边赋予方向后,每个点的入度与出度之差小于 ...

  4. 2015 多校赛 第四场 1010 (hdu 5336)

    Problem Description XYZ is playing an interesting game called "drops". It is played on a r ...

  5. 2015 多校赛 第四场 1009 (hdu 5335)

    Problem Description In an n∗m maze, the right-bottom corner is the exit (position (n,m) is the exit) ...

  6. hdu 5319 Painter(杭电多校赛第三场)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5319 Painter Time Limit: 2000/1000 MS (Java/Others)   ...

  7. hdu 5326 Work(杭电多校赛第三场)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5326 Work Time Limit: 2000/1000 MS (Java/Others)    M ...

  8. NOI.AC NOIP模拟赛 第三场 补记

    NOI.AC NOIP模拟赛 第三场 补记 列队 题目大意: 给定一个\(n\times m(n,m\le1000)\)的矩阵,每个格子上有一个数\(w_{i,j}\).保证\(w_{i,j}\)互不 ...

  9. 【杂题总汇】HDU多校赛第十场 Videos

    [HDU2018多校赛第十场]Videos 最后一场比赛也结束了…… +HDU传送门+ ◇ 题目 <简要翻译> 有n个人以及m部电影,每个人都有一个快乐值.每场电影都有它的开始.结束时间和 ...

随机推荐

  1. IO文件读取

    /** *按字节读取文件 */@Testpublic void readerByte() { File file = new File("D:\\BindCheckControllerTes ...

  2. HDU 2451 Simple Addition Expression(找规律,考验智商)

    题目 最近比赛的题目好多签到题都是找规律的考验智商的题目啊,,,我怎么越来越笨了,,,, 通过列举,可以发现规律: 从左往右按位扫这个数: 当数的长度大于1时: 当首位大于3时,答案就是4*4*4*… ...

  3. 面试题:你能写一个Vue的双向数据绑定吗?

    在目前的前端面试中,vue的双向数据绑定已经成为了一个非常容易考到的点,即使不能当场写出来,至少也要能说出原理.本篇文章中我将会仿照vue写一个双向数据绑定的实例,名字就叫myVue吧.结合注释,希望 ...

  4. 一次vue-cli 2.x项目打包优化经历(优化xlsx插件)

    一.分析各模块打包后大小 用vue-cli创建的项目,已经集成 webpack-bundle-analyzer.详见文件 build/webpack.prod.conf.js,代码如下: if (co ...

  5. 《hello-world》第八次团队作业:Alpha冲刺-Scrum Meeting 5

    项目 内容 这个作业属于哪个课程 2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十二 团队作业8:软件测试与Alpha冲刺 团队名称 <hello--worl ...

  6. iOS学习笔记18-CoreData你懂的

    一.CoreData介绍 CoreData是iOS5之后新出来的的一个框架, 是对SQLite进行一层封装升级后的一种数据持久化方式. 它提供了对象<-->关系映射的功能,即能够将OC对象 ...

  7. SSM框架下实现导出功能

    导出:将当前页面表格里值传到excel表格中. 一.页面js //下载excel $("#download").click( function() { var param = $( ...

  8. nyoj 310二分+dinic

    #include<stdio.h> #include<queue> #include<string.h> using namespace std; #define ...

  9. [poj3735] Training little cats_矩乘快速幂

    Training little cats poj-3735 题目大意:给你n个数,k个操作,将所有操作重复m次. 注释:三种操作,将第i个盒子+1,交换两个盒子中的个数,将一个盒子清空.$1\le m ...

  10. Myeclipse10完美破解过程

    Myeclipse10完美破解过程 1.假设还没有破解文件的话,能够先到这里去下载破解件 http://download.csdn.net/download/wangcunhuazi/7874155 ...