#include<bits/stdc++.h>
using namespace std;
int t;
long long a,b;
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--)
{
cin>>a>>b;
if(b==0||a==b)
{
cout<<1<<"\n";
continue;
}
long long l=1,r=a;
while(l<=r)
{
long long mid=(l+r)/2;
// cout<<mid<<" ";
if((a-mid*b)<mid)
{
r=mid-1;
}
else
{
l=mid+1;
}
}
long long ansl=l;
l=1,r=a;
while(l<=r)
{
long long mid=(l+r)/2;
if(b*mid<=a)
{
l=mid+1;
}
else
{
r=mid-1;
}
}
cout<<r-ansl+1<<"\n";
}
return 0;
}
真服了,这个第一题难度远远大于第二题,还不知道怎么做