题目链接:

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. Something-Summary

    1.Combinatorial Mathematics 1.1 Bell Number: \(B_n\)表示元素个数为n的集合划分成若干个不相交集合的方案数. \(B_{n + 1} = \sum_{ ...

  2. express,中间件(body-parser),req.body获取不到参数(含postman发请求的方法)

    问题描述: 最近在做毕设,express 里边的中间件(body-parser)失效,req.body获取不到任何值,req.query能获取到值.一开始加body-parser中间件是有用的,直到昨 ...

  3. SpringMVC响应Ajax请求(@Responsebody注解返回页面)

    项目需求描述:page1中的ajax请求Controller,Controller负责将service返回的数据填充到page2中,并将page2整个页面返回到page1中ajax的回调函数. 一句话 ...

  4. 定制表格头, 学习Core Graphic 的第二部分, 阴影与玻璃效果.

    //定制表格头, 学习Core Graphic 的第二部分, 阴影与玻璃效果. https://github.com/comcuter/testsnippets/commit/e96f62d115ef ...

  5. 【Android工具类】验证码倒计时帮助类CountDownButtonHelper的实现

    转载请注明出处:http://blog.csdn.net/zhaokaiqiang1992 我们在做有关短信验证码功能的时候.为了防止用户无休止的获取短信验证码,或者是误操作.造成验证码混乱的情况.我 ...

  6. js进阶 13-3 jquery动画显示隐藏,滑动,淡入淡出的本质是什么

    js进阶 13-3 jquery动画显示隐藏,滑动,淡入淡出的本质是什么 一.总结 一句话总结:分别改变display,高度,opacity透明度这三种属性. 1.fade系列函数有哪四个? fade ...

  7. Launcher Activity在开机时重新启动两次解决的方法

    今天在看log的时候发现,Launcher activity会被onDestroy掉一次.然后再重新启动. 可能原因推測: 1.横竖屏切换 2.MCC MNC等Configuration改变引起的 M ...

  8. js实现点击不同的按钮后各自返回被点击的次数

    js实现点击不同的按钮后各自返回被点击的次数 一.总结 1.注意:返回的不是三个按钮总的点击数,而是每一个的 2.用全局变量的话每一个按钮要多一个函数,用闭包就很方便 二.js实现点击不同的按钮后各自 ...

  9. PatentTips - Data Plane Packet Processing Tool Chain

    BACKGROUND The present disclosure relates generally to systems and methods for providing a data plan ...

  10. word多出空标题,样式是列出段落 - -显示时,选择不勾选“隐藏文字”

    word多出空标题,样式是列出段落