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

题意:定义了一个函数F(x),表示x这个数的不同素数因数的个数,然后给你一个区间[L,R],问你任意区间内不同的两个数的最大公约数是多少,这里要发现1000000范围内的最大不同素数因数个数是7,所以用dp[i][j]保存从1到i这i个数不同素数因数的个数。这里先预处理1~1000000的数的不同素数因数的个数,可以用普通素数筛法(这里线性筛法好像不能用,因为线性筛法只能求出这个数的素数因数个数和因数个数)。

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define maxn 1000000
int vis[maxn+10],prime[maxn+10],tot,dp[maxn+10][10],cnt[maxn+10];
void init()
{
int i,j;cnt[1]=0;
for(i=2;i<=maxn;i++){
if(!vis[i]){
cnt[i]=1;
for(j=2*i;j<=maxn;j+=i){
vis[j]=1;
cnt[j]++;
}
}
}
for(i=1;i<=7;i++){
dp[1][i]=0;
}
for(i=2;i<=maxn;i++){
for(j=1;j<=7;j++){
dp[i][j]=dp[i-1][j];
}
dp[i][cnt[i]]++;
}
} int main()
{
int n,m,i,j,T;
int num1[10];
init();
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(i=1;i<=7;i++){
num1[i]=dp[m][i]-dp[n-1][i];
}
if(num1[7]>=2){
printf("7\n");continue;
}
if(num1[6]>=2){
printf("6\n");continue;
}
if(num1[5]>=2){
printf("5\n");continue;
}
if(num1[4]>=2){
printf("4\n");continue;
}
if(num1[3]>=2 || (num1[6]==1 && num1[3]==1)){
printf("3\n");continue;
}
if(num1[2]>=2 || (num1[6]==1 && num1[4]==1) || (num1[6]==1 && num1[2]==1) || (num1[4]==1 && num1[2]==1)){
printf("2\n");continue;
}
printf("1\n");
}
return 0;
}

hdu5317 RGCDQ的更多相关文章

  1. hdu5317 RGCDQ 统计

    // hdu5317 RGCDQ // // 题目大意: // // 给定一个闭区间[l,r],定义f(x)是x的不同的质因子的个数 // 比方: 12 = 2 * 2 * 3,是两种.所以f(x) ...

  2. 解题报告 之 HDU5317 RGCDQ

    解题报告 之 HDU5317 RGCDQ Description Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to ...

  3. hdu5317 RGCDQ (质因子种数+预处理)

    RGCDQ 题意:F(x)表示x的质因子的种数.给区间[L,R],求max(GCD(F(i),F(j)) (L≤i<j≤R).(2<=L < R<=1000000) 题解:可以 ...

  4. HDU-5317 RGCDQ ,暴力打表!

    RGCDQ 暴力水题,很可惜比赛时没有做出来,理清思路是很简单的. 题意:定义f(i)表示i的素因子个数,给你一段区间[l,r],求max_gcd(f(i),f(j)).具体细节参考题目. 思路:数据 ...

  5. HDU 5317 RGCDQ (数论素筛)

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

  6. 数学+dp HDOJ 5317 RGCDQ

    题目传送门 /* 题意:给一个区间,问任意两个数的素数因子的GCD最大 数学+dp:预处理出f[i],发现f[i] <= 7,那么用dp[i][j] 记录前i个f[]个数为j的数有几个, dp[ ...

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

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

  8. 2015 Multi-University Training Contest 3 1002 RGCDQ

    RGCDQ Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5317 Mean: 定义函数f(x)表示:x的不同素因子个数. 如:f ...

  9. HDU-5317

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

随机推荐

  1. MySQL的索引优化分析(一)

    一.SQL分析 性能下降.SQL慢.执行时间长.等待时间长 查询语句写的差 索引失效关联查询太多join(设计缺陷) 单值索引:在user表中给name属性创建索引,create index idx_ ...

  2. python学习笔记 | macOS Big Sur动态壁纸食用指南

    目录 前言 爬虫篇 壁纸使用篇 后记 前言 北京时间23日凌晨1点,苹果WWDC2020大会开幕.在发布会上,苹果正式发布了新版macOS,并将其命名为"Big Sur". 相比于 ...

  3. buuctf—web—Easy Calc

    启动靶机,查看网页源码,发现关键字 $("#content").val() 是什么意思: 获取id为content的HTML标签元素的值,是JQuery,     ("# ...

  4. 阿里云 RTC QoS 屏幕共享弱网优化之若干编码器相关优化

    屏幕共享是视频会议中使用频率最高的功能之一,但在实际场景中用户所处网络环境复杂,常遇到丢包或者拥塞的情况,所以如何优化弱网环境下的用户体验也成为了音视频通信中重要的一环.本文主要分享阿里云 RTC Q ...

  5. python--or 和 and 表达式

    or表达式: 两边为一真一假,返回真: 两边都为假,返回右边: 两边都为真,返回左边: and表达式: 两边为一真一假,返回假: 两边都为假,返回左边: 两边都为真,返回右边:

  6. spring mvc + mybaties + mysql 完美整合cxf 实现webservice接口 (服务端、客户端)

    spring-3.1.2.cxf-3.1.3.mybaties.mysql 整合实现webservice需要的完整jar文件 地址:http://download.csdn.net/detail/xu ...

  7. 记一次 RocketMQ broker 因内存不足导致的启动失败

    原创:西狩 编写日期 / 修订日期:2020-01-12 / 2020-01-12 版权声明:本文为博主原创文章,遵循 CC BY-SA-4.0 版权协议,转载请附上原文出处链接和本声明. 背景 该小 ...

  8. 1.8V转3V,1,8V转3.3V电源芯片的规格书参数

    1.8V电平如何稳压稳定输出3V或者3.3V,就需要用到1.8V转3V,1,8V转3.3V电源芯片,就PW5100(低功耗,外围简单),PW5200A是可调输出电压,可以输出电压根据外围电阻来设置命令 ...

  9. linux通过ntp同步时间

    1.安装服务 yum install ntp ##安装ntp服务,这个和ntpdate不一样哦,用这个比较好 systemctl start ntpd.service ###启动服务 systemct ...

  10. WPF TabControl美化

    <Window.Resources> <!-- TabItem的样式 --> <Style TargetType="{x:Type TabItem}" ...