BZOJ 3834 Poi2014 Solar Panels 数论

题目大意:给定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;
}
时间: 2024-12-22 12:58:59

BZOJ 3834 Poi2014 Solar Panels 数论的相关文章

BZOJ 3834 [Poi2014]Solar Panels 数学

题意: n组询问,每次问smin<=x<=smax, wmin<=y<=wmax时gcd(x, y)的最大值. 解析: md以前有个结论忘了结果这题坑我30分钟+ 我们显然可以找到一个结论. 令gcd(x,y)=z; 那么显然有(smin-1)/z #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace

【bzoj3834】[Poi2014]Solar Panels 数论

题目描述 Having decided to invest in renewable energy, Byteasar started a solar panels factory. It appears that he has hit the gold as within a few days  clients walked through his door. Each client has ordered a single rectangular panel with specified w

BZOJ3834 [Poi2014]Solar Panels

我和数论没完了.. 这题就是要找 a ∈ [mn1, mx1], b ∈ [mn2, mx2] 的最大 gcd(a, b) 不妨设 mx1 < mx2,如果mn1 > mn2则答案就是mx1 否则我们要找到一个最大的x使得 a ∈ [mn1 / x, mx1 / x], b ∈ [mn2 / x, mx2 / x], 满足gcd(a, b) ≥ 1 分块搞搞,判断一下区间大小≥1就好了 1 /***************************************************

【BZOJ】【2219】数论之神

中国剩余定理+原根+扩展欧几里得 题解:http://blog.csdn.net/regina8023/article/details/44863519 新技能get√: 1 LL Get_yuangen(LL p,LL phi){ 2 int c=0; 3 for(int i=2;i*i<=phi;i++) 4 if (phi%i==0) 5 f[++c]=i,f[++c]=phi/i; 6 for(int g=2;;g++){ 7 int j; 8 for(j=1;j<=c;j++) if

BZOJ 3524: [Poi2014]Couriers

3524: [Poi2014]Couriers Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 1905  Solved: 691[Submit][Status][Discuss] Description 给一个长度为n的序列a.1≤a[i]≤n.m组询问,每次询问一个区间[l,r],是否存在一个数在[l,r]中出现的次数大于(r-l+1)/2.如果存在,输出这个数,否则输出0. Input 第一行两个数n,m.第二行n个数,a[i].接下来m行,

bzoj 3831: [Poi2014]Little Bird

3831: [Poi2014]Little Bird Description In the Byteotian Line Forest there are   trees in a row. On top of the first one, there is a little bird who would like to fly over to the top of the last tree. Being in fact very little, the bird might lack the

BZOJ 3524: [Poi2014]Couriers( 主席树 )

卡我空间.... 这道题应该是主席树入门题...无修改 , 离散化都不用...出题人业界良心啊 一开始的空白树我 build 出来结果就多了整整 2n 个 Node , 然后就 MLE 了... ( 双倍经验 , 另一道见上图 ) ---------------------------------------------------------------------------------------------- #include<cstdio> #include<cstring&g

bzoj 3832: [Poi2014]Rally(线段树+拓扑排序)

3832: [Poi2014]Rally Time Limit: 20 Sec  Memory Limit: 128 MBSec  Special Judge Submit: 113  Solved: 56 [Submit][Status][Discuss] Description An annual bicycle rally will soon begin in Byteburg. The bikers of Byteburg are natural long distance cyclis

Bzoj 3505: [Cqoi2014]数三角形 数论

3505: [Cqoi2014]数三角形 Time Limits: 1000 ms  Memory Limits: 524288 KB  Detailed Limits Description Input 输入一行,包含两个空格分隔的正整数m和n. Output 输出一个正整数,为所求三角形数量. Sample Input 输入1: 1 1 输入2: 2 2 Sample Output 输出1: 4 输出2: 76 Data Constraint 对于30%的数据 1<=m,n<=10 对于1