RGCDQ

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2818    Accepted Submission(s): 1108

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
/*
hdu 5317 合数分解+预处理 problem:
查找区间[l,r]中 gcd(F[a[i]],F[a[j]])的最大值. F[x]为x的分解出的质因子种类数 solve:
可以先计算一下,1e6时质因子最多有7个. 所以可以dp[maxn][7]先预处理出质因子个数的前缀和.
然后查找 1~7谁出现了2次及以上 hhh-2016-08-21 10:38:45
*/
#pragma comment(linker,"/STACK:124000000,124000000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#define lson ch[0]
#define rson ch[1]
#define ll long long
#define clr(a,b) memset(a,b,sizeof(a))
#define key_val ch[ch[root][1]][0]
using namespace std;
const int maxn = 1000000;
const int INF = 1e9+10; int prime[maxn+1]; void getPrime()
{
memset(prime,0,sizeof(prime));
for(int i = 2;i <= maxn;i++)
{
if(!prime[i]) prime[++prime[0]] = i;
for(int j = 1;j <= prime[0] && prime[j] <= maxn/i;j++)
{
prime[prime[j]*i] = 1;
if(i % prime[j] == 0) break;
}
}
} int getFactor(int x)
{
int t = x;
int fant = 0;
for(int i = 1;prime[i] <= t/prime[i];i++)
{
if(t % prime[i] == 0)
{
fant ++;
while(t % prime[i] == 0)
t /= prime[i];
}
}
if(t != 1)
fant ++;
return fant;
} int dp[maxn+1][7]; int main()
{
getPrime();
for(int i = 0;i <= 7;i++)
dp[0][i] = 0;
for(int i = 1;i <= maxn;i++)
{
int t = getFactor(i);
for(int j = 0;j < 7;j++)
{
if(t == j+1)
dp[i][j] = dp[i-1][j] + 1;
else
dp[i][j] = dp[i-1][j];
}
}
int T;
int a,b;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&a,&b);
int tMax = 0;
for(int i = 6;i >= 0;i--)
{
if(dp[b][i] - dp[a-1][i] > 1)
{
tMax =i;
break;
}
}
printf("%d\n",tMax+1);
}
}

  

hdu 5317 合数分解+预处理的更多相关文章

  1. hdu 4777 树状数组+合数分解

    Rabbit Kingdom Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  2. HDU 4610 Cards (合数分解,枚举)

    Cards Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  3. HDU 4497 GCD and LCM (合数分解)

    GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  4. hdu 5317 RGCDQ(前缀和)

    题目链接:hdu 5317 这题看数据量就知道需要先预处理,然后对每个询问都需要在 O(logn) 以下的复杂度求出,由数学规律可以推出 1 <= F(x) <= 7,所以对每组(L, R ...

  5. hdu_4497GCD and LCM(合数分解)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4497 GCD and LCM Time Limit: 2000/1000 MS (Java/Other ...

  6. Perfect Pth Powers pku-1730(筛+合数分解)

    题意:x可以表示为bp, 求这个p的最大值,比如 25=52, 64=26,  然后输入x 输出 p 就是一个质因子分解.算法.(表示数据上卡了2个小时.) 合数质因子分解模板. ]; ]; ; ;n ...

  7. pku1365 Prime Land (数论,合数分解模板)

    题意:给你一个个数对a, b 表示ab这样的每个数相乘的一个数n,求n-1的质数因子并且每个指数因子k所对应的次数 h. 先把合数分解模板乖乖放上: ; ans != ; ++i) { ) { num ...

  8. Gym101889J. Jumping frog(合数分解+环形dp预处理)

    比赛链接:传送门 题目大意: 一只青蛙在长度为N的字符串上跳跃,“R”可以跳上去,“P”不可以跳上去. 字符串是环形的,N-1和0相连. 青蛙的跳跃距离K的取值范围是[1, N-1],选定K之后不可改 ...

  9. hdu 4568 Hunter(spfa预处理 + 状压dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4568 思路:首先spfa预处理出每对宝藏之间的最短距离以及宝藏到边界的最短距离,然后dp[state] ...

随机推荐

  1. B-end

    Beta冲刺成员名单和工作量比例 姓名 学号 负责内容 工作量比例 张梨贤 170327109 负责企业人员的委托/收回授权.第三方机构的委托授权管理.分级统计展示.分级列表展示 26% 黄腾飞 17 ...

  2. day9

    Alpha冲刺Day9 一:站立式会议 今日安排: 经过为期5天的冲刺,基本完成企业人员模块的开发.因第三方机构与企业存在委托的关系.第三方人员对于风险的自查.风险列表的展示以及自查风险的统计展示(包 ...

  3. SQL数据库开发中的一些经典代码

    1.按姓氏笔画排序: Select * From TableName Order By CustomerName Collate Chinese_PRC_Stroke_ci_as  2.数据库加密: ...

  4. iOS开发-即时通信XMPP

    1. 即时通信 1> 概述 即时通讯(Instant Messaging)是目前Internet上最为流行的通讯方式,各种各样的即时通讯软件也层出不穷,服务提供商也提供了越来越丰富的通讯服务功能 ...

  5. Spring mvc中junit测试遇到com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException错误怎么解决

    今天遇到图片中的错误,纠结了一下,弄清楚了怎么从控制台中读取错误信息,并修改错误. com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: ...

  6. 用nodejs 开发的智能提示

    用nodejs 开发的智能提示 时间:2014-07-01 03:50:18 类别:搜索引擎 访问: 2576 次 感谢:http://lutaf.com/223.htm 智能提示对于搜索非常重要,相 ...

  7. C# 启动 SQL Server 服务

    //首先要添加 System.ServiceProcess.dll 引用 ServiceController sc = new ServiceController("MSSQLSERVER& ...

  8. 新概念英语(1-45)The boss's letter

    新概念英语(1-45)The boss's letter Why can't Pamela type the letter? A:Can you come here a minute, please, ...

  9. SpringCloud的EurekaClient : 客户端应用访问注册的微服务(无断路器场景)

    演示客户端应用如何访问注册在EurekaServer里的微服务 一.概念和定义 采用Ribbon或Feign方式访问注册到EurekaServer中的微服务.1.Ribbon实现了客户端负载均衡,2. ...

  10. JavaScript实现面向对象

    /* js实现面向对象的方法 */ // 1 工厂模型 不推荐 function Person(name , sex , age){ obj = {}; obj.name = name; obj.se ...