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. Python web服务器

    Python 配置wsgi接口# 引入Python wsgi包 from wsgiref.simple_server import make_server # 撰写服务器端程序代码 def Appli ...

  2. Scala Option类型

    转载自: Scala 初学者指南, 这里有一系列很棒的文章 类型 Option 可能你已经见过它在 Map API 中的使用:在实现自己的提取器时,我们也用过它, 然而,它还需要更多的解释. 你可能会 ...

  3. cocos2d 判断旋转矩形是否包含某个点

    本来想画个图演示一下,但是折腾了一会发现画不好,我的win10系统没有安装office,以后再看的话再补上吧.不废话了. 如图所以,如果判断点P是否被矩形A所包含,非常容易.那么如果矩形A以中心点逆时 ...

  4. Python内置函数(36)——reversed

    英文文档: reversed(seq) Return a reverse iterator. seq must be an object which has a __reversed__() meth ...

  5. sql优化基础篇

    优化的步骤: 0.先sql运行看看是否真的很慢,注意设置SQL_NO_CACHE 1.where条件单表查,锁定最小返回记录表.这句话的意思是把查询语句的where都应用到表中返回的记录数最小的表开始 ...

  6. spring-oauth-server实践:使用授权方式四:client_credentials 模式下access_token做业务!!!

    spring-oauth-server入门(1-10)使用授权方式四:client_credentials 模式下access_token做业务!!! 准备工作 授权方式四::客户端方式: 服务网关地 ...

  7. Python基础学习篇章四

    一. Python数据类型之字典 1. 键的排序:for循环 由于字典不是序列,因此没有可靠的从左至右的顺序.这就导致当建立一个字典,将它打印出来,它的键也许会以与我们输入时的不同的顺序出现.有时候我 ...

  8. Extensions in UWP Community Toolkit - Mouse Cursor

    概述 UWP Community Toolkit Extensions 中有一个为 Mouse 提供的扩展 - Mouse Cursor Extensions,本篇我们结合代码详细讲解 Mouse C ...

  9. 整理一下 System.Linq.Enumerable 类中的那些比较少用的方法

    Linq 虽然用得多,但是里面有一些方法比较少用,因此整理一下.Enumerable 类的所有方法可以在 MSDN 上查阅到:https://msdn.microsoft.com/zh-cn/libr ...

  10. java将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。

    首先我们的算法是:例如 输入的是 90 1.找到90的最小公约数(1除外)是 2 2.然后把公约数 2 输出 3.接着用 90 / 2 = 45 (如果这里是素数,就结束,否则继续找最小公约数) 4. ...