bool vis[maxn]; int prime[maxn]; int mu[maxn]; ll f[maxn]; int tot;
voideular(){ vis[0] = vis[1] = true; mu[1] = 1; for (int i = 2; i < maxn; i++) { if (!vis[i]) { prime[tot++] = i; mu[i] = -1; } for (int j = 0; j < tot && i * prime[j] < maxn; j++) { vis[i * prime[j]] = true; mu[i * prime[j]] = -mu[i]; if (i % prime[j] == 0) { mu[i * prime[j]] = 0; break; } } } }
voidinit(){ for (int i = 0; i < tot; i++) { for (int j = prime[i]; j < maxn; j += prime[i]) { f[j] += mu[j / prime[i]]; } } for (int i = 1; i < maxn; i++) { f[i] += f[i - 1]; } }
intmain(){ eular(); init(); int T; scanf("%d", &T); while (T--) { int n, m; scanf("%d%d", &n, &m); int tmp = min(n, m); ll ans = 0; for (int l = 1, r; l <= tmp; l = r + 1) { r = min(n / (n / l), m / (m / l)); ans += (f[r] - f[l - 1]) * (n / l) * (m / l); } printf("%lld\n", ans); } return0; }