RGCDQ

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

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
 
Source

/**
题意:给出一个区间,然后求区间的数的质因子个数之间的最大公约数
思路:枚举2~N之间的每个数的质因子的个数,计算L ~ R 之间的数的
质因子的个数,因为之前打过表,2~N之间的最大的质因子个数是7
所以,计算L ~ R 之间的1~7出现的次数,然后进行统计枚举,
被自己蠢dao了
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#define maxn 1000000+10
using namespace std;
int num[maxn];
int sum[maxn][];
int mmap[];
int temp[];
void init()
{
memset(num,,sizeof(num));
memset(sum,,sizeof(sum));
for(int i=;i<maxn;i++)
{
if(num[i]) continue;
num[i] = ;
for(int j=;j*i<maxn;j++)
{
num[j*i] ++;
}
}
sum[][] = ;
for(int i=;i<maxn;i++)
{
for(int j=;j<=;j++)
{
sum[i][j] = sum[i-][j];
}
sum[i][num[i]]++;
}
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
scanf("%d",&T);
init();
while(T--)
{
int left,right;
scanf("%d %d",&left,&right);
int cet = ;
memset(temp,,sizeof(temp));
memset(mmap,,sizeof(mmap));
for(int i=;i<=;i++)
{
mmap[i] = sum[right][i] - sum[left][i];
if(num[left] == i)mmap[i]++;
if(mmap[i] >= )
{
temp[cet++] = i;
temp[cet++] = i;
}
else if(mmap[i] == )
temp[cet++] = i;
}
int mmax = ;
for(int i=;i<cet;i++)
{
for(int j=i+;j<cet;j++)
{
mmax = max(mmax,__gcd(temp[i],temp[j]));
}
}
printf("%d\n",mmax);
}
return ;
}

HDU-5317的更多相关文章

  1. hdu 5317 RGCDQ(前缀和)

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

  2. hdu 5317 合数分解+预处理

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

  3. hdu 5317 RGCDQ (2015多校第三场第2题)素数打表+前缀和相减求后缀(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5317 题意:F(x) 表示x的不同质因子的个数结果是求L,R区间中最大的gcd( F(i) , F(j ...

  4. HDU 5317 RGCDQ(素数个数 多校2015啊)

    题目链接:pid=5317" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5317 Prob ...

  5. HDU 5317 RGCDQ (数论素筛)

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

  6. ACM学习历程—HDU 5317 RGCDQ (数论)

    Problem Description Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more an ...

  7. 2015 多校赛 第三场 1002 (hdu 5317)

    Description Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more and more i ...

  8. 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ

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

  9. HDU 5317 RGCDQ (质数筛法,序列)

    题意:从1~1000,000的每个自然数质因子分解,不同因子的个数作为其f 值,比如12=2*2*3,则f(12)=2.将100万个数转成他们的f值后变成新的序列seq.接下来T个例子,每个例子一个询 ...

  10. HDU 5317 RGCDQ

    题意:f(i)表示i的质因子个数,给l和r,问在这一区间内f(i)之间任意两个数最大的最大公倍数是多少. 解法:先用筛法筛素数,在这个过程中计算f(i),因为f(i)不会超过7,所以用一个二维数组统计 ...

随机推荐

  1. 洛谷 P2324 [SCOI2005]骑士精神 解题报告

    P2324 [SCOI2005]骑士精神 题目描述 输入输出格式 输入格式: 第一行有一个正整数T(T<=10),表示一共有N组数据.接下来有T个5×5的矩阵,0表示白色骑士,1表示黑色骑士,* ...

  2. Linux之根文件系统的构建20160611

    说一下LINUX根文件系统的构建: 制作文件系统 1. 交叉编译busybox 安装:make install CONFIG_PREFIX=/work/nfs_root/fs_mini_mdev_ne ...

  3. swift的UIbutton

    override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, ...

  4. 注册google账号时出现手机号的问题

    注册谷歌账号时出现此电话号码无法用于进行验证 这主要是86和手机号之间有一个空格造成的,把这个空格删除就可以了

  5. 使用 Rational AppScan 保证 Web 应用的安全性,第 2 部分: 使用 Rational AppScan 应对 Web 应用攻击

    1 当前 Web 安全现状 互联网的发展历史也可以说是攻击与防护不断交织发展的过程.目前,全球因特网用户已达 13.5 亿,用户利用网络进行购物.银行转账支付和各种软件下载,企业用户更是依赖于互联网构 ...

  6. css常见水平居中

    行内元素居中 常见行内元素如文本,图片等居中时,通常是给父元素设置text-align:center 来实现.例如 HTML: <body> <div>我是文字,我要居中显示& ...

  7. css 常用苹方字体

    // 苹方-简 常规体 font-family: PingFangSC-Regular, sans-serif; // 苹方-简 极细体 font-family: PingFangSC-Ultrali ...

  8. 转:PriorityQueue

    转自:PriorityQueue 本文github地址 Java中PriorityQueue通过二叉小顶堆实现,可以用一棵完全二叉树表示.本文从Queue接口函数出发,结合生动的图解,深入浅出地 分析 ...

  9. 51Nod 1092 回文字符串 | 最长公共子序列变形

    求字符串和其逆的最长公共子序列,需要添加的字符数就为长度-最长公共子序列长 #include "stdio.h" #include "string.h" #de ...

  10. CODE FESTIVAL 2017 qual B C - 3 Steps

    Score : 500 points Problem Statement Rng has a connected undirected graph with N vertices. Currently ...