RGCDQ

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

Submit

Status

Practice

HDU 5317

Appoint description:

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

没有想到所有的数中最大才为7

直接构造二维前缀数组记录在它之前的各个个数的数目;

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <list>
#include <algorithm>
#define RR freopen("output.txt","r",stdout)
#define WW freopen("input.txt","w",stdin)
typedef long long LL; using namespace std; const int MAX = 1000010; int num[MAX]; int dp[MAX][8]; int main()
{
memset(num,0,sizeof(num));
memset(dp,0,sizeof(dp));
for(int i=2; i<MAX; i++)//开始写成(i*i<MAX)了,手残
{
if(!num[i])
{
num[i]=1;
for(int j=2; j*i<MAX; j++)
{
num[j*i]++;
}
}
}
dp[2][1]=1;
for(int i=3; i<MAX; i++)
{ for(int j=1; j<=7; j++)
{
dp[i][j]=dp[i-1][j];
} dp[i][num[i]]++;
} int L,R;
int T;
int ans;
int s[8];
scanf("%d",&T);
while(T--)
{
scanf("%d %d",&L,&R);
ans=0;
for(int i=1; i<=7; i++)
{
s[i]=dp[R][i]-dp[L-1][i];
}
if(s[7]>=2)
{
ans=7;
}
else if(s[6]>=2)
{
ans=6;
}
else if(s[5]>=2)
{
ans=5;
}
else if(s[4]>=2)
{
ans=4;
}
else if(s[3]>=2)
{
ans=3;
}
else if(s[6]&&s[3])
{
ans=3;
}
else if(s[2]>=2)
{
ans=2;
}
else if(s[6]&&s[2])
{
ans=2;
}
else if(s[6]&&s[4])
{
ans=2;
}
else if(s[4]&&s[2])
{
ans=2;
}
else
{
ans=1;
}
printf("%d\n",ans);
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

多校3- RGCDQ 分类: 比赛 HDU 2015-07-31 10:50 2人阅读 评论(0) 收藏的更多相关文章

  1. Nginx介绍 分类: Nginx 服务器搭建 2015-07-13 10:50 19人阅读 评论(0) 收藏

    海量请求,高性能服务器. 对比Apache, Apache:稳定,开源,跨平台,重量级,不支持高度并发的web服务器. 由此,出现了Lighttpd与Nignx:轻量级,高性能. 发音:engine ...

  2. 全面解析sizeof(下) 分类: C/C++ StudyNotes 2015-06-15 10:45 263人阅读 评论(0) 收藏

    以下代码使用平台是Windows7 64bits+VS2012. sizeof作用于基本数据类型,在特定的平台和特定的编译中,结果是确定的,如果使用sizeof计算构造类型:结构体.联合体和类的大小时 ...

  3. 全面解析sizeof(上) 分类: C/C++ StudyNotes 2015-06-15 10:18 188人阅读 评论(0) 收藏

    以下代码使用平台是Windows7 64bits+VS2012. sizeof是C/C++中的一个操作符(operator),其作用就是返回一个对象或者类型所占的内存字节数,使用频繁,有必须对齐有个全 ...

  4. MS SQL 合并结果集并求和 分类: SQL Server 数据库 2015-02-13 10:59 92人阅读 评论(0) 收藏

    业务情景:有这样一张表:其中Id列为表主键,Name为用户名,State为记录的状态值,Note为状态的说明,方便阅读. 需求描述:需要查询出这样的结果:某个人某种状态的记录数,如:张三,待审核记录数 ...

  5. 菜鸟学习-C语言函数参数传递详解-结构体与数组 分类: C/C++ Nginx 2015-07-14 10:24 89人阅读 评论(0) 收藏

    C语言中结构体作为函数参数,有两种方式:传值和传址. 1.传值时结构体参数会被拷贝一份,在函数体内修改结构体参数成员的值实际上是修改调用参数的一个临时拷贝的成员的值,这不会影响到调用参数.在这种情况下 ...

  6. jQuery中的on()和click()的区别 分类: 前端 HTML jQuery 2014-11-06 10:26 96人阅读 评论(0) 收藏

    HTML页面代码 <div> <h1>Click</h1> <button class="add">Click me to add ...

  7. 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活 分类: dp 2015-05-21 10:50 14人阅读 评论(0) 收藏

    Description 急!灾区的食物依然短缺! 为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种大米,每种大米都是袋装产品,其价格不等,并 ...

  8. OC基础:内存(内存管理) 分类: ios学习 OC 2015-06-25 16:50 73人阅读 评论(0) 收藏

    自动释放池: @autoreleasepool { } 内存管理机制       谁污染,谁治理 垃圾回收机制:gc(Garbage collection),由系统管理内存,开发人员不需要管理. OC ...

  9. 改变HTML中超链接的显示样式 分类: C1_HTML/JS/JQUERY 2014-08-27 10:11 595人阅读 评论(0) 收藏

    更详细的内容请参考:http://www.w3school.com.cn/tags/tag_a.asp HTML中的代码如下: <a class="news_title" t ...

随机推荐

  1. js方法和prototype

    JS中的方法可以分为三类 1.对象方法 2.类方法 3.原型方法 例: function People(name) { this.name=name; //对象方法 this.Introduce=fu ...

  2. 自己使用Fresco时遇到的相关问题

    Fresco是facebook推出的一款强大的android图片处理库,github地址:https://github.com/facebook/fresco 里面有官方的使用配置文档,而且是中文的. ...

  3. HDU 5000 Clone(离散数学+DP)(2014 ACM/ICPC Asia Regional Anshan Online)

    Problem Description After eating food from Chernobyl, DRD got a super power: he could clone himself ...

  4. HDU 4064 Carcassonne(插头DP)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4064 Problem Description Carcassonne is a tile-based ...

  5. HDU 4897 Little Devil I(树链剖分)(2014 Multi-University Training Contest 4)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4897 Problem Description There is an old country and ...

  6. struts文件上传(多文件)

    第01步:配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version= ...

  7. SpringMVC配制全局的日期格式

    SpringMVC文件配制: <mvc:annotation-driven> <!-- 处理responseBody 里面日期类型 --> <mvc:message-co ...

  8. MyEclipse安装插件的三种方法和使用心得

    本文讲解MyEclipse(MyEclipse10)的三种方法,以TestNG为例 Eclipse update site URL:  http://beust.com/eclipse. 一.通过My ...

  9. zw版【转发·台湾nvp系列Delphi例程】HALCON Histogram

    zw版[转发·台湾nvp系列Delphi例程]HALCON Histogram unit Unit1;interfaceuses Windows, Messages, SysUtils, Varian ...

  10. 「Ruby && Sqlite3」How to install sqlite3 for ruby? (solve: sqlite-ruby no such file...)

    error message:           no such file .... 安装 gem install sqlite3-ruby -- --with-sqlite3-dir=/usr/lo ...