HDU 5317 RGCDQ(素数个数 多校2015啊)
题目链接: pid=5317" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5317
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)
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
See the sample for more details.
2
2 3
3 5
1
1
题意:
一个函数 :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啊)的更多相关文章
- hdu 5317 RGCDQ(前缀和)
题目链接:hdu 5317 这题看数据量就知道需要先预处理,然后对每个询问都需要在 O(logn) 以下的复杂度求出,由数学规律可以推出 1 <= F(x) <= 7,所以对每组(L, R ...
- 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 ...
- 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 ...
- HDU 5317 RGCDQ (数论素筛)
RGCDQ Time Limit: 3000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Submit Status ...
- ACM学习历程—HDU 5317 RGCDQ (数论)
Problem Description Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more an ...
- HDU 5294 Tricks Device(多校2015 最大流+最短路啊)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5294 Problem Description Innocent Wu follows Dumb Zha ...
- HDU 5317 RGCDQ
题意:f(i)表示i的质因子个数,给l和r,问在这一区间内f(i)之间任意两个数最大的最大公倍数是多少. 解法:先用筛法筛素数,在这个过程中计算f(i),因为f(i)不会超过7,所以用一个二维数组统计 ...
- HDU 5317 RGCDQ (质数筛法,序列)
题意:从1~1000,000的每个自然数质因子分解,不同因子的个数作为其f 值,比如12=2*2*3,则f(12)=2.将100万个数转成他们的f值后变成新的序列seq.接下来T个例子,每个例子一个询 ...
- 2015 HDU 多校联赛 5317 RGCDQ 筛法求解
2015 HDU 多校联赛 5317 RGCDQ 筛法求解 题目 http://acm.hdu.edu.cn/showproblem.php? pid=5317 本题的数据量非常大,測试样例多.数据 ...
随机推荐
- rhel5安装 oracle10
readhat 安装11gr2文档 需要注意的地方:必须关掉的 1,防火墙:2,SElinux . root 用户运行 setup 命令可关防火墙与SElinux 修改网络配置文件,一定要重启此文 ...
- python之经典猜数字
题目:猜数字1.让用户输入1-20,猜数字,可以猜5次.2.每次有提示,大了,或者小了!3.如果超过5次,提示game over. # !/usr/bin/env python # -*- codin ...
- jmeter--错误之Not able to find Java executable or version. Please check your Java installation. errorlevel=2
学习jmeter中遇到的问题: 'findstr' 不是内部或外部命令,也不是可运行的程序或批处理文件. Not able to find Java executable or version. Pl ...
- 【例题 6-11 UVA-297】Quadtrees
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 发现根本不用存节点信息. 遇到了叶子节点且为黑色,就直接覆盖矩阵就好(因为是并集); [代码] #include <bits/ ...
- Scala在挖财的应用实践--转载
原文地址:http://www.infoq.com/cn/articles/scala-architecture-wacai 编者按:本文是根据ArchSummit大会上挖财资深架构师王宏江的演讲&l ...
- OC学习篇之---归档和解挡
今天我们来看一下OC中的一个重要知识点:归档 OC中的归档就是将对象写入到一个文件中,Java中的ObjectInputStream和ObjectOutputStream来进行操作的.当然在操作的这些 ...
- Apache与weblogic整合实战(独家研究)
用apache来处理外界的请求,再把请求转发给wls,这样就行突破wls express版本号的5用户限制 详细配置例如以下 copy ${WLS_Server}/server/lib下的mod_wl ...
- cocos 关于文件名称的各种坑 各种斜杠坑
cocos 全部文件路径 的斜杠 必须 用 / 而不能够用 \ 不然编译到安卓各种坑 相对路径 第一个字符不可 带 / /*比如 res/test.png 这样的应该是标准的 /res/test.p ...
- Socket编程模型之完毕port模型
转载请注明来源:viewmode=contents">http://blog.csdn.net/caoshiying?viewmode=contents 一.回想重叠IO模型 用完毕例 ...
- php.ini 修改上传文件的限制
打开php.ini,首先找到file_uploads = on ;是否允许通过HTTP上传文件的开关.默认为ON即是开upload_tmp_dir ;文件上传至服务器上存储临时文件的地方,如果没指定就 ...