码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 5317(RGCDQ-统计)

时间:2015-08-18 19:20:41      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

RGCDQ

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


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))技术分享 (Li<jR)技术分享
 

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
 

Author
ZSTU
 

Source
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:  5405 5404 5403 5402 5401 
 

统计f[i]出现次数即可



#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (1000000+10)
typedef long long ll;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}

int P[MAXN],siz=0,b[MAXN]={0};  
int gcd(int a,int b){if (b) return gcd(b,a%b);return a;}
void make_prime(int n)  
{  
    Fork(i,2,n)  
    {  
        if (!b[i])  
        {  
            P[++siz]=i;  
        }  
        For(j,siz)  
        {  
            if (P[j]*i>n) break;  
            b[P[j]*i]=b[i];
			if (gcd(P[j],i)==1) b[P[j]*i]++; 
            if (i%P[j]==0) break;  
        }  
    }  
}   
int t[8],cnt[MAXN][8]={0};
const int n=1000000,mm=7;
int main()
{
//	freopen("B.in","r",stdin);
	
	make_prime(n);
	For(i,n) 
	{
		For(j,7)
			cnt[i][j]=cnt[i-1][j]+(bool)(b[i]+1==j);
	}
	
	
//	For(i,30) cout<<i<<' '<<b[i]+1<<endl;	

	int T;cin>>T;
	while(T--)
	{
		int l,r;
		scanf("%d%d",&l,&r);
	
		For(i,7) t[i]=cnt[r][i]-cnt[l-1][i];	
		
		int ans=0;
		For(i,7)
			For(j,7)
			{
				if (t[i]&&t[j]&&((i!=j)||(t[i]>1))) ans=max(ans,gcd(i,j));
			}	
		printf("%d\n",ans);
		
	}
	return 0;
}





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

HDU 5317(RGCDQ-统计)

标签:

原文地址:http://blog.csdn.net/nike0good/article/details/47756301

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!