HDU 5317 RGCDQ
题意:f(i)表示i的质因子个数,给l和r,问在这一区间内f(i)之间任意两个数最大的最大公倍数是多少。
解法:先用筛法筛素数,在这个过程中计算f(i),因为f(i)不会超过7,所以用一个二维数组统计前i个数中每个f(i)出现的次数,当询问l和r时,用num[r] - num[l - 1],得到这一区间内的结果,然后讨论一下,如果出现过6和3则答案可能为3,如果出现过4和2则答案可能为2,如果某数字出现两次及以上则答案可能是这个数字,以上几种情况取最大值,即为答案。
代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long using namespace std; int f[1000005];
int num[1000005][8];
void init()
{
for(int i = 2; i < 1000005; i++)
{
if(f[i] == 0)
{
f[i] = 1;
for(int j = i + i; j < 1000005; j += i)
f[j]++;
}
}
for(int i = 2; i < 1000005; i++)
{
memcpy(num[i], num[i - 1], sizeof num[i - 1]);
num[i][f[i]]++;
}
}
int main()
{
init();
int T;
while(~scanf("%d", &T))
{
while(T--)
{
int l, r;
scanf("%d%d", &l, &r);
int a[8] = {0};
for(int i = 1; i < 8; i++)
a[i] = num[r][i] - num[l - 1][i];
int ans = 1;
for(int i = 7; i > 0; i--)
if(a[i] > 1)
{
ans = i;
break;
}
if(a[4] && a[2])
ans = max(ans, 2);
if(a[6] && a[3])
ans = max(ans, 3);
printf("%d\n", ans);
}
}
return 0;
}
HDU 5317 RGCDQ的更多相关文章
- hdu 5317 RGCDQ(前缀和)
题目链接:hdu 5317 这题看数据量就知道需要先预处理,然后对每个询问都需要在 O(logn) 以下的复杂度求出,由数学规律可以推出 1 <= F(x) <= 7,所以对每组(L, R ...
- HDU 5317 RGCDQ(素数个数 多校2015啊)
题目链接:pid=5317" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5317 Prob ...
- HDU 5317 RGCDQ (数论素筛)
RGCDQ Time Limit: 3000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Submit Status ...
- 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 ...
- ACM学习历程—HDU 5317 RGCDQ (数论)
Problem Description Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more an ...
- 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 (质数筛法,序列)
题意:从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 本题的数据量非常大,測试样例多.数据 ...
- hdu 5317 合数分解+预处理
RGCDQ Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
随机推荐
- C#设计模式学习资料--外观模式
http://www.cf17.com/html/article/172.html http://blog.csdn.net/scucj/article/details/1374657 http:// ...
- iis7、mvc2.0 文件上传配置方案
http://blog.csdn.net/useruse/article/details/5602495
- 1074: [SCOI2007]折纸origami - BZOJ
Description 桌上有一张边界平行于坐标轴的正方形纸片,左下角的坐标为(0,0),右上角的坐标为(100,100).接下来执行n条折纸命令.每条命令用两个不同点P1(x1,y1)和P2(x2, ...
- 1015: [JSOI2008]星球大战starwar - BZOJ
Description 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治者整个星系.某一天,凭着一个偶然的机遇,一支反抗军摧毁了帝国的超级武器,并攻下了星系中几乎所有的星球.这些星球通过 ...
- 团体程序设计天梯赛-练习集L1-018. 大笨钟
L1-018. 大笨钟 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 微博上有个自称“大笨钟V”的家伙,每天敲钟催促码农们爱惜 ...
- Chp2: Linked List
2.2 Implement an algorithm to find the kth to last element of a singly linked list. Just using " ...
- SQL Server CONVERT() 函数
http://www.w3school.com.cn/sql/func_convert.asp 定义和用法 CONVERT() 函数是把日期转换为新数据类型的通用函数. CONVERT() 函数可以用 ...
- CI中获取读操作的结果集行数+获取写操作的影响行数
本质:读操作,用mysql_num_rows函数,写操作用mysql_affected_rows函数 mysql_num_rows() 返回结果集中行的数目.此命令仅对 SELECT 语句有效.要取得 ...
- php构造函数construct用法注意事项
<?php class A { //特别注意,这里的下划线为两个 function __construct() { echo "I am the constructor of A.&l ...
- MyEclipse下查看Java API帮助文档
每次重装JDK或者升级JDK时,都会忘了如何使MyEclipse关联帮助文档.然后,再花十几分钟重新google搜索,麻烦! 首先下载Javadoc api帮助文档,google搜一下就行了. MyE ...