码迷,mamicode.com
首页 > 其他好文 > 详细

莫比乌斯反演(HDU5663)

时间:2020-07-06 15:54:27      阅读:40      评论:0      收藏:0      [点我收藏+]

标签:bsp   ros   class   loading   nbsp   思路   png   ima   pos   

题意:

技术图片

 

思路:

技术图片

 

代码:

 1 const int maxn = 10000000 + 10;
 2 ll n, m, a;
 3 ll miu[maxn], v[maxn];
 4 ll sum[maxn];
 5 void Eratosthenes(int n) {
 6     for (int i = 1; i <= n; i++)miu[i] = 1, v[i] = 0;
 7     for (int i = 2; i <= n; ++i) {
 8         if (v[i])continue;
 9         miu[i] = -1;
10         for (int j = 2 * i; j <= n; j += i) {
11             v[j] = 1;
12             if ((j / i) % i == 0)miu[j] = 0;
13             else miu[j] *= -1;
14         }
15     }
16     for (int i = 1; i * i <= n; ++i) {
17         for (int j = i * i; j <= n; j += i * i) {
18             sum[j] += miu[j / (i * i)];
19         }
20     }
21     for (int i = 1; i <= n; ++i)sum[i] += sum[i - 1];
22 }
23 ll cal(int n, int m) {
24     ll ans = 0, pos;
25     for (int i = 1; i <= min(n, m); i = pos + 1) {
26         pos = min(n / (n / i), m / (m / i));
27         ans += 1ll * (sum[pos] - sum[i - 1]) * (n / i) * (m / i);
28     }
29     return ans;
30 }
31 
32 int main() {
33     Eratosthenes(10000000);
34     int T = read();
35     while (T--) {
36         n = read(), m = read();
37         printf("%lld\n", n * m - cal(n, m));
38     }
39 }

莫比乌斯反演(HDU5663)

标签:bsp   ros   class   loading   nbsp   思路   png   ima   pos   

原文地址:https://www.cnblogs.com/JayShao/p/13254799.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!