#include<cstdio>
#include<algorithm>

using namespace std;

long long calc(long long l,long long r,long long t)
{
	if(t<=l)return 0;
	if(t>=r)return t*(r-l+1)-(l+r)*(r-l+1)/2;
	return calc(l,t,t)+calc(t+1,r,t);
}

int main()
{
	int T=0;scanf("%d",&T);
	while(T--)
	{
		long long x=0,y=0;scanf("%lld%lld",&x,&y);
		long long ans=calc(1,x/(1+y),y);//printf("%lld ",ans);
		long long l=x/(1+y)+1,r=0;
		while(l<=x)
		{
			r=x/(x/l);long long t=x/l;
			ans+=calc(l,r,t-1);
			l=r+1;
		}
		printf("%lld\n",ans);
	}
}
