这么写为啥会 WA on 24(最后一个点)啊
求个神教教 /kel
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
#define int long long
inline int read(){
register int x=0,f=0,ch=getchar();
while('0'>ch||ch>'9')f^=ch=='-',ch=getchar();
while('0'<=ch&&ch<='9')x=x*10+(ch^'0'),ch=getchar();
return f?-x:x;
}
signed main(){
int Test=read();
while(Test--) {
int a,b;
a=read(),b=read();
if(a >= b) {
printf("%lld\n", a-b);
}else {
int ans = a + b;
int l = 1,r;
while(l <= b - 1) {
r = (b - 1) / ((b - 1) / l);
int x = max( (b-1) / r + 1 - a , 0ll );
int y = l * (a + x) - b;
ans = min(ans, x + y);
l = r + 1;
}
printf("%lld\n", ans);
}
}
return 0;
}