Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Problem Description
“WTF! While everyone has his girl(gay) friend, I only have my keyboard!” Tired of watching others’ affair, Hillan burst into scream, which made him decide not to hold it back. “All right, I am giving you a question. If you answer correctly, I will be your girl friend.” After listening to Hillan, Girl replied,
“What is the value of ∑i=1n∑j=1mf(i,j), where f(i,j)=0 if gcd(i,j) is a square number and f(i,j)=1 if gcd(i,j) is not a square number(gcd(i,j) means the greatest common divisor of x and y)?” But Hillan didn’t have enough Intelligence Quotient to give the right answer. So he turn to you for help.
Input
The first line contains an integer T(1≤T≤10,000)——The number of the test cases. For each test case, the only line contains two integers n,m(1≤n,m≤10,000,000) with a white space separated.
Output
For each test case, the only line contains a integer that is the answer.
Sample Input
2
1 2333333
10 10
Sample Output
0 33
Hint
In the first test case, obviously f(i,j) always equals to 0, because i always equals to 1 and gcd(i,j) is always a square number(always equals to 1).
int mu[maxn], pri[maxn], sum[maxn]; bool vis[maxn]; int cnt;
voidMobius(){ cnt = 0; mu[1] = 1; for(int i = 2; i < maxn; ++i){ if(!vis[i]){ pri[++cnt] = i; mu[i] = -1; }for(int j = 1; j <= cnt; ++j){ if(i * pri[j] >= maxn) break; vis[i * pri[j]] = true; if(i % pri[j]== 0){ mu[i * pri[j]] = 0; break; }mu[i * pri[j]] = - mu[i]; } } int t = sqrt(maxn); for(int i = 1; i <= t; ++i){ int x = i * i; for(int j = x, k = 1; j < maxn; j+= x, ++k) sum[j] += mu[k]; }for(int i = 1; i < maxn; ++i) sum[i] += sum[i-1]; }
LL solve(int b, int d){ LL ans = 0, pos; for(int i = 1; i <= b; i = pos+1){ pos = min(b/(b/i), d/(d/i)); ans += 1LL * (b/i) * (d/i) * (sum[pos] - sum[i-1]); }return ans; }
intmain(){ Mobius(); int t; scanf("%d", &t); while(t--){ int n, m; scanf("%d %d", &n, &m); LL ans = 1LL*n*m; if(n > m) swap(n, m); ans -= solve(n, m); printf("%lld\n", ans); }return0; }