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 ;
}
 
 
 
 
 

最新文章

  1. logrotate关于日志轮询和分割
  2. Winform自定义窗体样式,实现标题栏可灵活自定义
  3. [cocos2dx]让CCScrollView支持分页
  4. ED/EP系列4《圈存指令》
  5. Python中的List,Tuple,Dic,Set
  6. Flash加载网页内容
  7. SpringMVC+Mybatis架构中的问题记录
  8. Java学习笔记11---静态成员变量、静态代码块、成员变量及构造方法的初始化或调用顺序
  9. mysql explain用法和结果的含义
  10. Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be ope
  11. FineUIPro/Mvc/Core/JS v4.2.0 发布了(老牌ASP.NET控件库,WebForms,ASP.NET MVC,Core,JavaScript)!
  12. Java的动手动脑(七)
  13. python爬虫出现的状态码
  14. 线程安全的集合类、CopyOnWrite机制介绍(转)
  15. 如何修改Oracle Enterprise Linux时区?
  16. Python中的高级turtle(海龟)作图(续)
  17. 理解C++类的继承方式(小白)
  18. php 内置函数JSON处理
  19. hadoop之 YARN配置参数剖析—RM与NM相关参数
  20. SQL语句优化 (一) (52)

热门文章

  1. Spring处理自动装配的歧义性
  2. 学不好Linux?我们分析看看正确的学习方法是什么-马哥教育
  3. BZOJ 2894: 世界线 广义后缀自动机
  4. Oracle数据库的自动备份脚本
  5. Opencv学习之路—Opencv下基于HOG特征的KNN算法分类训练
  6. POJ-2135-Farm Tour(最大费用最小流)模板
  7. CentOS 7.2安装配置Vsftp服务器
  8. mac上的svn命令
  9. 如何实现在scrapy调试爬虫
  10. BZOJ——T 2097: [Usaco2010 Dec]Exercise 奶牛健美操