#include <cstdio>
#include <cstring>
#include <cstdarg>
#include <algorithm>
#include <list>
#include <queue>
#include <vector>
#include <cmath>
using namespace std;
int calc_phi(int x)
{
if(x == 1)return 1;
int a = x;
int m = sqrt(x+0.5);
for(int i = 2; i <= m; i++)
{
if(!(x%i))a = a/i*(i-1);
while(!(x%i))x /= i;
}
if(x>1) a = a/x*(x-1);
return a;
}
int main()
{
freopen("gcd.in", "r", stdin);
freopen("gcd.out", "w", stdout);
int t;
scanf("%d", &t);
while(t--)
{
int n, z;
scanf("%d %d", &n, &z);
long long ans = 0;
int m = sqrt(n+0.5);
for(int i = 1; i <= m; i++)
{
if(n%i)continue;
int k = n/i;
if(k >= z)ans += calc_phi(i);
if(k != i && i >= z)ans += calc_phi(k);
}
printf("%lld\n", ans);
}
return 0;
}