题目链接
题解
容易想到对于(gcd(x,y) = D),(d)的倍数一定存在于两个区间中
换言之
[lfloor frac{a - 1}{D}
floor < lfloor frac{b}{D}
floor
]
[lfloor frac{c - 1}{D}
floor < lfloor frac{d}{D}
floor
]
整除分块即可做到(O(nsqrt{max{b}}))
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 100005,maxm = 100005,INF = 1000000000;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
int main(){
register int T = read(),a,b,c,d,M,ans,A,B,C,D;
while (T--){
a = read() - 1; b = read(); c = read() - 1; d = read();
M = max(b,d); ans = 1;
for (register int i = 1,nxt; i <= M; i = nxt + 1){
nxt = INF;
A = a / i,B = b /i,C = c / i,D = d / i;
if (A) nxt = min(nxt,a / A);
if (B) nxt = min(nxt,b / B);
if (C) nxt = min(nxt,c / C);
if (D) nxt = min(nxt,d / D);
if (A < B && C < D) ans = nxt;
}
printf("%d
",ans);
}
return 0;
}