YY的GCD

很抱歉,这篇文章鸽了
回家了写\(QAQ\)


\(2019/9/5 UPD:\)这几天有点累太久没熬夜了不太习惯只能在机房颓一颓代码,周末回去把笔记本上的推导过程丢上来吧
先丢个代码在这里,坑待补

// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define int long long
#define N (10000000 + 5)
using namespace std;
inline void read(int &cnt) {
	cnt = 0; int f = 1; char c = getchar();
	while (!isdigit(c)) {if (c == '-') f = -f; c = getchar();}
	while (isdigit(c)) {cnt = (cnt << 3) + (cnt << 1) + (c ^ 48); c = getchar();}
	cnt *= f;
}
int prime[N], T, mu[N], f[N], tot, n, m, s[N];
int ans = 0;
bool isprime[N];
void init() {
	mu[1] = 1;
	for (register int i = 2; i <= N - 3; ++i) {
		if (!isprime[i]) prime[++tot] = i, mu[i] = -1;
		for (register int j = 1; j <= tot; ++j) {
			if (prime[j] * i > N - 3) break;
			isprime[prime[j] * i] = 1; if (i % prime[j] == 0) break;
			mu[prime[j] * i] = -mu[i];
		}
	}
	for (register int i = 1; i <= N - 3; ++i) 
		for (register int j = 1; j <= tot; ++j)
			if (prime[j] * i <= N - 3) f[prime[j] * i] += mu[i]; else break;
	for (register int i = 1; i <= N - 3; ++i) s[i] = s[i - 1] + f[i]; 
}
signed main() {
	read(T);
	init();
	while (T--) {
		ans = 0;
		read(n), read(m);
		if (n > m) swap(n, m);
		for (int l = 1, r; l <= n; l = r + 1) {
			int x1 = n / l, x2 = m / l;
			r = min(n / x1, m / x2);
			ans += (s[r] - s[l - 1]) * x1 * x2;
		} printf("%lld\n", ans);
	}
	return 0;
}
posted @ 2019-09-04 22:02  kma_093  阅读(114)  评论(0编辑  收藏  举报