2015 多校赛 第三场 1002 (hdu 5317)
2024-09-06 11:41:17
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.
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.
See the sample for more details.
Sample Input
2
2 3
3 5
Sample Output
1
1
注意到F值不大。直接用筛法预处理出F值。用数组num[i][j]记录前 i 个数中有多少个 j。
然后暴力。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define maxn 1000005
int t,l,r,F[maxn],num[maxn][],cnt[],ans;
void init(){
for(int i=;i<=;i++){
if(F[i]==){
for(int j=i<<;j<=;j+=i)
F[j]++;
F[i]=;
}
}
for(int i=;i<=;i++){
for(int j=;j<=;j++){
num[i][j]=num[i-][j];
if(F[i]==j) num[i][j]++;
}
}
}
int main(){
init();
scanf("%d",&t);
while(t--){
ans=;
scanf("%d%d",&l,&r);
for(int i=;i<=;i++){
cnt[i]=num[r][i]-num[l-][i];
if(cnt[i]>) ans=i;
}
if(cnt[]&&cnt[]) ans=max(ans,);
if(cnt[]&&cnt[]) ans=max(ans,);
if(cnt[]&&cnt[]) ans=max(ans,);
if(cnt[]&&cnt[]) ans=max(ans,);
printf("%d\n",ans);
}
return ;
}
最新文章
- logrotate关于日志轮询和分割
- Winform自定义窗体样式,实现标题栏可灵活自定义
- [cocos2dx]让CCScrollView支持分页
- ED/EP系列4《圈存指令》
- Python中的List,Tuple,Dic,Set
- Flash加载网页内容
- SpringMVC+Mybatis架构中的问题记录
- Java学习笔记11---静态成员变量、静态代码块、成员变量及构造方法的初始化或调用顺序
- mysql explain用法和结果的含义
- Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be ope
- FineUIPro/Mvc/Core/JS v4.2.0 发布了(老牌ASP.NET控件库,WebForms,ASP.NET MVC,Core,JavaScript)!
- Java的动手动脑(七)
- python爬虫出现的状态码
- 线程安全的集合类、CopyOnWrite机制介绍(转)
- 如何修改Oracle Enterprise Linux时区?
- Python中的高级turtle(海龟)作图(续)
- 理解C++类的继承方式(小白)
- php 内置函数JSON处理
- hadoop之 YARN配置参数剖析—RM与NM相关参数
- SQL语句优化 (一) (52)