T组数据,求
首先,膜拜一下PoPoQQQ大神及其题解
然后,有一个神奇的结论:
要证上式,只需证
分开考虑每个质数
再令
然后可以莫比乌斯反演了:
然后用筛法筛出
看来还需要锻炼自己的数学功底啊
#include <cstdio>
#include <algorithm>
#define ll long long
#define M 50000
using namespace std;
int mu[M + 5], n, m, pri[M], top, d[M + 5], f[M + 5];
bool mrk[M + 5];
void getmu()
{
mu[1] = d[1] = 1;
for(int i = 2; i <= M; ++i)
{
if(!mrk[i])
{
pri[top++] = i;
mu[i] = -1;
d[i] = 2;
f[i] = 1;
}
for(int j = 0; j < top && i * pri[j] <= M; ++j)
{
mrk[i * pri[j]] = true;
if(i % pri[j] == 0)
{
mu[i * pri[j]] = 0;
f[i * pri[j]] = f[i] + 1;
d[i * pri[j]] = d[i] / (f[i] + 1) * (f[i] + 2);
break;
}
mu[i * pri[j]] = -mu[i];
d[i * pri[j]] = (d[i] << 1);
f[i * pri[j]] = 1;
}
}
for(int i = 2; i <= M; ++ i)
{
d[i] += d[i - 1];
mu[i] += mu[i - 1];
}
}
inline ll work(int n, int m)
{
if(n > m) swap(n, m);
ll ans = 0;
for(int i = 1, j; i <= n; i = j + 1)
{
j = min(n / (n / i), m / (m / i));
ans += (ll)(mu[j] - mu[i - 1]) * (ll)d[n / i] * (ll)d[m / i];
}
return ans;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("d.txt", "r", stdin);
freopen("a.txt", "w", stdout);
#endif
int T;
getmu();
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n, &m);
printf("%lld\n", work(n, m));
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/t14t41t/article/details/47808233