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。
然后暴力。
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. using namespace std;
  6. #define maxn 1000005
  7. int t,l,r,F[maxn],num[maxn][],cnt[],ans;
  8. void init(){
  9. for(int i=;i<=;i++){
  10. if(F[i]==){
  11. for(int j=i<<;j<=;j+=i)
  12. F[j]++;
  13. F[i]=;
  14. }
  15. }
  16. for(int i=;i<=;i++){
  17. for(int j=;j<=;j++){
  18. num[i][j]=num[i-][j];
  19. if(F[i]==j) num[i][j]++;
  20. }
  21. }
  22. }
  23. int main(){
  24. init();
  25. scanf("%d",&t);
  26. while(t--){
  27. ans=;
  28. scanf("%d%d",&l,&r);
  29. for(int i=;i<=;i++){
  30. cnt[i]=num[r][i]-num[l-][i];
  31. if(cnt[i]>) ans=i;
  32. }
  33. if(cnt[]&&cnt[]) ans=max(ans,);
  34. if(cnt[]&&cnt[]) ans=max(ans,);
  35. if(cnt[]&&cnt[]) ans=max(ans,);
  36. if(cnt[]&&cnt[]) ans=max(ans,);
  37. printf("%d\n",ans);
  38. }
  39. return ;
  40. }
 
 
 
 
 

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. matlab数值数据的表示方法,输出数据以及相关函数

    数据类型的分类: 1.整型 无符号整型和带符号整形 带符号整形的最大值是127 >>x=int8(129) 输出结果是x=127 >>x=unit8(129) 输出结果是x=1 ...

  2. MHA的MySQL高可用方案实战

    功能: 1)master的故障切换(keepalived VIP的飘移) 2)主从复制角色的提升和重新转向 其中master 对外提供写服务,备选master2(实际的slave提供读服务,slave ...

  3. Django - 视图获取请求头

    1.urls.py(url和函数对应关系) 2.通过request.evniron,返回request的所有信息,用索引的方式,获取用户请求头信息. 3.也可以通过key,value方式,来展示请求头 ...

  4. Linux内核源码特殊用法

    崇拜并且转载的: http://ilinuxkernel.com/files/5/Linux_Kernel_Source_Code.htm Linux内核源码特殊用法 1 前言 Linux内核源码主要 ...

  5. uvalive 3231

    3231 - Fair ShareAsia - Seoul - 2004/2005You are given N processors and M jobs to be processed. Two ...

  6. Optimizing web servers for high throughput and low latency

    转自:https://blogs.dropbox.com/tech/2017/09/optimizing-web-servers-for-high-throughput-and-low-latency ...

  7. 救济金发放(The Dole Queue, UVa 133)

    n(n<20)个人站成一圈,逆时针编号为1-n.有两个官员,A从1开始逆时针数,B从n开 始顺时针数.在每一轮中,官员A数k个就停下来,官员B数m个就停下来(注意有可能两个 官员停在同一个人上) ...

  8. 00.Python中下划线的5种含义

    转自这里 先放上 简短的"速查表",罗列了五种Python下划线模式的含义: 模式 举例 含义 单前导下划线 _var 命名约定,仅供内部使用.通常不会由Python解释器强行执行 ...

  9. Python - 模块(二)

    目录 Python - 模块(二) re re下面的方法 logging os Python - 模块(二) re re模块提供了正则表达式的相关操作 主要字符介绍: . 通配符,除了换行符之外的任意 ...

  10. 洛谷 P1943 LocalMaxima_NOI导刊2009提高(1)

    我们先考虑第i大数,比它大的数有(n-i)个,显然要使i是Local Maxima,比它大的数必须放在它后面,那么它是Local Maxima的期望是: 那么n个数中Local Maxima个数的期望 ...