标签:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; const int maxn = 10000010; int mu[maxn], prime[maxn], vis[maxn], sum[maxn]; int cnt; LL a, b; void mobi(int n) { mu[1] = 1; for(int i = 2; i <= n; i++) { if(!vis[i]) { prime[cnt++] = i; mu[i] = -1; sum[i] = 1; } for(int j = 0; j < cnt && i*prime[j] <= n; j++) { vis[i*prime[j]] = 1; if(i%prime[j]) { mu[i*prime[j]] = -mu[i]; sum[i*prime[j]] = mu[i]-sum[i]; } else { mu[i*prime[j]] = 0; sum[i*prime[j]] = mu[i]; break; } } } for(int i = 1; i <= n; i++) sum[i] += sum[i-1]; } LL cal(LL n, LL m) { LL ans = 0; if(n > m) swap(n, m); int pos; for(int i = 1; i <= n; i = pos+1) { pos = min(n/(n/i), m/(m/i)); ans += (sum[pos]-sum[i-1])*(m/i)*(n/i); } return ans; } int main() { mobi(10000000); int T; scanf("%d", &T); while(T--) { scanf("%lld %lld", &a, &b); LL ans = cal(a, b); printf("%lld\n", ans); } return 0; }
标签:
原文地址:http://blog.csdn.net/u011686226/article/details/44198993