Given integers N and M, how many integer X satisfies 1<=X<=N and (X,N)>=M.
The first line of input is an integer T(T<=100) representing the number of test cases. The following T lines each contains two numbers N and M (2<=N<=1000000000, 1<=M<=N), representing a test case.
For each test case,output the answer on a single line.
voidprime(){ memset(ipr, true, sizeof(ipr)); ipr[1] = false; int N = sqrt(PN) + 0.5; for (int i = 2; i <= N; i++) { if (ipr[i]) { int d = i == 2 ? i : 2 * i; for (int j = i * i; j <= PN; j += d) { ipr[j] = false; } } } for (int i = 1; i <= PN; i++) { if (ipr[i]) pri[++pn] = i; } }
voideprime(){ //not verify memset(ipr, true, sizeof(ipr)); ipr[1] = false; phi[1] = 1; for (int i = 2; i <= PN; i++) { if (ipr[i]) pri[++pn] = i, phi[i] = i - 1; for (int j = 1; j <= pn && pri[j] * i <= PN; j++) { ipr[pri[j] * i] = false; if (i % pri[j]) phi[i * pri[j]] = phi[i] * phi[pri[j]]; else { phi[i * pri[j]] = phi[i] * pri[j]; break; } } } }
inteuler_phi(int n){ int ans = n; for (int i = 2; i * i <= n; i++) if (n % i == 0) { ans = ans / i * (i - 1); while (n % i == 0) n /= i; } if (n > 1) ans = ans / n * (n - 1); return ans; }
ll speed(ll a, ll b, ll p){ ll cur = a, ans = 1; while (b) { if (b & 1) ans = ans * cur % p; cur = cur * cur % p; b >>= 1; } return ans % p; }
ll gcd(ll a, ll b){ return b == 0 ? a : gcd(b, a % b); }
int T, n, m, cnt, ans; int a[100020], b[100020];
voidfj(int t){ cnt = 0; for (int i = 1; i <= pn && pri[i] * pri[i] <= t; i++) { if (t % pri[i] == 0) a[++cnt] = pri[i], b[cnt] = 0; while (t % pri[i] == 0) { b[cnt]++; t /= pri[i]; } } if (t > 1) a[++cnt] = t, b[cnt] = 1; if (cnt == 0) a[1] = 1, b[1] = 1; }
voiddfs(int t, int cur){ if (t == cnt + 1) { if (cur >= m) { ans += euler_phi(n / cur); } return; } dfs(t + 1, cur); for (int i = 1; i <= b[t]; i++) { cur *= a[t]; dfs(t + 1, cur); } }
intmain(){ io_opt; eprime(); cin >> T; while (T--) { cin >> n >> m; ans = 0; fj(n); dfs(1, 1); cout << ans << endl; } return0; }