题目链接:

pid=5317" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5317

Problem 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
 
Source

题意:

一个函数 :f(x)它的值是x的素因子不同的个数;

如:f(2) = 1, f(3) = 1。

当中(L<=i<j<=R),即区间内随意不相等的两个数的最大公约数的最大值;

PS:

由于2*3*5*7*11*13*17 > 1e6!

所以f(x)的值最大为7;

我们先打表求出每一个f(x)的值;

//int s[maxn][10];//前i个F中j的个数

然后再利用前缀和s[r][i] - s[l-1][i]。

求出区间[l, r]的值。

代码例如以下:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
#define maxn 1000000+7
int prim[maxn];
int s[maxn][10];//前i个F中j的个数
int GCD(int a, int b)
{
if(b==0)
return a;
return GCD(b, a%b);
}
void init()
{
memset(prim, 0, sizeof(prim));
memset(s, 0, sizeof(s));
for(int i = 2; i < maxn; i++)
{
if(prim[i]) continue;
prim[i] = 1;
for(int j = 2; j * i < maxn; j++)
{
prim[j*i]++;//不同素数个数
}
}
s[2][1] = 1;
for(int i = 3; i < maxn; i++)
{
for(int j = 1; j <= 7; j++)
{
s[i][j] = s[i-1][j];
}
s[i][prim[i]]++;
}
}
int main()
{
int t;
int l, r;
init();
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&l,&r);
int c[17];
int k = 0;
for(int i = 1; i <= 7; i++)
{
int tt = s[r][i] - s[l-1][i];
if(tt >= 2)//超过两个以上记为2个就可以
{
c[k++] = i;
c[k++] = i;
}
else if(tt == 1)
{
c[k++] = i;
}
}
int maxx = 1;
for(int i = 0; i < k-1; i++)
{
for(int j = i+1; j < k; j++)
{
int tt = GCD(c[i],c[j]);
maxx = max(maxx, tt);
}
}
printf("%d\n",maxx);
}
return 0;
}

HDU 5317 RGCDQ(素数个数 多校2015啊)的更多相关文章

  1. hdu 5317 RGCDQ(前缀和)

    题目链接:hdu 5317 这题看数据量就知道需要先预处理,然后对每个询问都需要在 O(logn) 以下的复杂度求出,由数学规律可以推出 1 <= F(x) <= 7,所以对每组(L, R ...

  2. hdu 5317 RGCDQ (2015多校第三场第2题)素数打表+前缀和相减求后缀(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5317 题意:F(x) 表示x的不同质因子的个数结果是求L,R区间中最大的gcd( F(i) , F(j ...

  3. 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ

    RGCDQ Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  4. HDU 5317 RGCDQ (数论素筛)

    RGCDQ Time Limit: 3000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status ...

  5. ACM学习历程—HDU 5317 RGCDQ (数论)

    Problem Description Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more an ...

  6. HDU 5294 Tricks Device(多校2015 最大流+最短路啊)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5294 Problem Description Innocent Wu follows Dumb Zha ...

  7. HDU 5317 RGCDQ

    题意:f(i)表示i的质因子个数,给l和r,问在这一区间内f(i)之间任意两个数最大的最大公倍数是多少. 解法:先用筛法筛素数,在这个过程中计算f(i),因为f(i)不会超过7,所以用一个二维数组统计 ...

  8. HDU 5317 RGCDQ (质数筛法,序列)

    题意:从1~1000,000的每个自然数质因子分解,不同因子的个数作为其f 值,比如12=2*2*3,则f(12)=2.将100万个数转成他们的f值后变成新的序列seq.接下来T个例子,每个例子一个询 ...

  9. 2015 HDU 多校联赛 5317 RGCDQ 筛法求解

    2015 HDU 多校联赛 5317 RGCDQ 筛法求解 题目  http://acm.hdu.edu.cn/showproblem.php? pid=5317 本题的数据量非常大,測试样例多.数据 ...

随机推荐

  1. 有关Canvas的一点小事--鼠标绘图

    1.  如何根据鼠标位置获取canvas上对应位置的x,y. 2.  canvas的图糊了,设置宽和高的方式不对. 3.鼠标绘图代码 之前听说过canvas这个元素,但是实际上并没有深入了解过.不过日 ...

  2. 洛谷 P3650 [USACO1.3]滑雪课程设计Ski Course Design

    P3650 [USACO1.3]滑雪课程设计Ski Course Design 题目描述 农民约翰的农场里有N座山峰(1<=N<=1000),每座山都有一个在0到100之间的整数的海拔高度 ...

  3. AIX上安装Oracle10G软件

    安装准备 (1)确认系统版本号.内核版本号 # oslevel –r   //查看操作系统版本号 //-08能够安装10g,-09能够安装11g watermark/2/text/aHR0cDovL2 ...

  4. 小贝_redis web管理界面工具安装

    RedisWEB管理界面工具安装 一.概述 二.文件下载 三.安装过程 一.概述 1.因为redis是基于C/S的方式开发.也就是说,仅仅要满足于redis的client通信要求的,都能够作为redi ...

  5. css中hack是什么

    css中hack是什么 一.总结 1.CSS hack:由于不同厂商的浏览器,比如Internet Explorer,Safari,Mozilla Firefox,Chrome等,或者是同一厂商的浏览 ...

  6. 自旋锁spinlock解析

    1 基础概念 自旋锁与相互排斥锁有点类似,仅仅是自旋锁不会引起调用者睡眠.假设自旋锁已经被别的运行单元保持.调用者就一直循环在那里看是否该自旋锁的保持者已经释放了锁."自旋"一词就 ...

  7. (转)chrome浏览器收藏夹(书签)的导出与导入

    导出chrome浏览器的书签到一个文件中.首先选择chrome浏览器的书签管理器菜单.然后点击“整理”,然后选择“将书签导出到html文件”. 步骤阅读 2 将导出的html文件保存,用于下次导入,这 ...

  8. LoaderManager使用具体解释(一)---没有Loader之前的世界

    来源: http://www.androiddesignpatterns.com/2012/07/loaders-and-loadermanager-background.html 感谢作者Alex ...

  9. Spring Cloud项目

    如何使用windows版Docker并在IntelliJ IDEA使用Docker运行Spring Cloud项目   如何使用windows版Docker并在IntelliJ IDEA使用Docke ...

  10. 在此页上的 ActiveX 控件和本页上的其它部份的交互可能不安全

    版权声明:转载时请以超链接形式标明文章原始出处和作者信息http://xqy266.blogbus.com/logs/66258230.html 在EOS6的项目中,如果采用VC++开发的Active ...