http://www.elijahqi.win/archives/2956
Description
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 width and height ranges.
The panels consist of square photovoltaic cells. The cells are available in all integer sizes, i.e., with the side length integer, but all cells in one panel have to be of the same size. The production process exhibits economies of scale in that the larger the cells that form it, the more efficient the panel. Thus, for each of the ordered panels, Byteasar would like to know the maximum side length of the cells it can be made of.
n组询问,每次问smin<=x<=smax, wmin<=y<=wmax时gcd(x, y)的最大值。
Input
The first line of the standard input contains a single integer N(1<=N<=1000): the number of panels that were ordered. The following lines describe each of those panels: the i-th line contains four integers Smin,Smax,Wmin,Wmax(1<=Smin<=Smax<=10^9,1<=Wmin<=Wmax<=10^9), separated by single spaces; these specify the minimum width, the maximum width, the minimum height, and the maximum height of the i-th panel respectively.
Output
Your program should print exactly n lines to the standard output. The i-th line is to give the maximum side length of the cells that the i-th panel can be made of.
Sample Input
4
3 9 8 8
1 10 11 15
4 7 22 23
2 5 19 24
Sample Output
8
7
2
5
HINT
Explanation: Byteasar will produce four solar panels of the following sizes: 8*8 (a single cell), 7*14 (two cells), 4*22 or 6*22 (22 or 33 cells respectively), and 5*20 (four cells).
Source
鸣谢zhonghaoxi
考虑将限制条件a-1,c-1然后再来考虑这个问题 问题似乎转化为我这次再去枚举gcd的数 然后求一下我这个gcd(x,y)的x,y都是谁 考虑到\frac{b}{g}的取值是只有sqrt的所以分块枚举即可 最后一个有效答案的块的答案一定符合要求
#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
inline char gc(){
static char now[1<<16],*S,*T;
if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
return *S++;
}
inline int read(){
int x=0,f=1;char ch=gc();
while(!isdigit(ch)) {if(ch=='-') f=-1;ch=gc();}
while(isdigit(ch)) x=x*10+ch-'0',ch=gc();
return x*f;
}
int main(){
freopen("bzoj3834.in","r",stdin);
int T=read();
while(T--){
int a=read()-1,b=read(),c=read()-1,d=read(),last=0,ans=1;
for (int i=1;i<=b&&i<=d;i=last+1){
last=min(b/(b/i),d/(d/i));
if (a/last<b/last&&c/last<d/last) ans=max(ans,last);
}printf("%d\n",ans);
}
return 0;
}