题目链接:

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. 使用solr的DIHandler 构建mysql大表全量索引,内存溢出问题的解决方法

    solr官方给出的解决方式是: DataImportHandler is designed to stream row one-by-one. It passes a fetch size value ...

  2. ASP.NET路径解惑

    对于ASP.NET的路径问题,一直都是云里雾里,没有去详细的理解,今天正好可以梳理一下它们之间的关系和使用方法.而若想明白路径的表示方式的使用方法和区别以及注意事项可以通过下面的几个概念来进一步加深: ...

  3. Android Intent的setClass和setClassName的区别

    setClass:跳转到与该工程下的(同一个Application中的)activity或者service setClassName:跳转到不同Applicaiton的activity或者servic ...

  4. Cronolog 分割 Tomcat8 Catalina.out日志 (转)

    默认情况下,tomcat的catalina.out日志文件是没有像其它日志一样,按日期进行分割,而是全部输出全部写入到一个catalina.out,这样日积月累就会造成.out日志越来越大,给管理造成 ...

  5. 洛谷 P1206 [USACO1.2]回文平方数 Palindromic Squares

    P1206 [USACO1.2]回文平方数 Palindromic Squares 题目描述 回文数是指从左向右念和从右向左念都一样的数.如12321就是一个典型的回文数. 给定一个进制B(2< ...

  6. android开发设计辅助工具整理

    1.Button设计工具button设计

  7. 机器学习分支:active learning、incremental learning、online machine learning

    1. active learning Active learning 是一种特殊形式的半监督机器学习方法,该方法允许交互式地询问用户(或者其他形式的信息源 information source)以获取 ...

  8. Web自动化测试 Selenium+Eclipse+Junit+TestNG+Python

    Selenium+Eclipse+Junit+TestNG+Python 第三步 下载Selenium IDE.SeleniumRC.IEDriverServer.SeleniumClient Dri ...

  9. DC中检查脚本错误

    dcprocheck    +     要检查的tcl文件

  10. System.Text.Encoding.Default

    string strTmp = "abcdefg某某某";int i= System.Text.Encoding.Default.GetBytes(strTmp).Length;/ ...