Description

求\((x,y)\)最大值,\(a\leqslant x\leqslant b,c\leqslant y\leqslant d,T\leqslant 10^3,a,b,c,d\leqslant 10^9\)

Solution

分块.

枚举gcd,判断是否存在,这个可以分块...

Code



/**************************************************************
Problem: 3834
User: BeiYu
Language: C++
Result: Accepted
Time:11116 ms
Memory:1288 kb
****************************************************************/

#include <bits/stdc++.h>
using namespace std;

int T,a,b,c,d,ans;
int main() {
for(scanf("%d",&T);T--;) {
scanf("%d%d%d%d",&a,&b,&c,&d);
a--,c--,ans=1;
for(int i=1,j;i<=min(b,d);i=j+1) {
j=min(b/(b/i),d/(d/i));
if(a/j<b/j && c/j<d/j) ans=max(ans,j);
}printf("%d\n",ans);
}return 0;
}