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

BZOJ 3834 Poi2014 Solar Panels 数论

时间:2015-01-12 21:05:49      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:bzoj   bzoj3834   数论   

题目大意:给定a,b,c,d,多次询问a<=x<=b,c<=x<=d时Gcd(x,y)的最大值ぽい

考虑枚举n=Gcd(x,y),那么[a,b]和[c,d]两个区间内存在n的倍数当且仅当floor(b/n)>floor((a-1)/n)且floor(d/n)>floor((c-1)/n)ぽい

由于后面的式子最多有O(√max(b,d))个取值,因此枚举商就可以了ぽい

1L和2L写了啥ぽい- -

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int a,b,c,d;
int main()
{
	int T,i,last;
	for(cin>>T;T;T--)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		int ans=1;
		for(i=1;i<=b&&i<=d;i=last+1)
		{
			last=min(b/(b/i),d/(d/i));
			if(b/last>(a-1)/last&&d/last>(c-1)/last)
				ans=max(ans,last);
		}
		printf("%d\n",ans);
	}
	return 0;
}


BZOJ 3834 Poi2014 Solar Panels 数论

标签:bzoj   bzoj3834   数论   

原文地址:http://blog.csdn.net/popoqqq/article/details/42646823

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