HDU 1695 - GCD

Posted nicetomeetu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 1695 - GCD相关的知识,希望对你有一定的参考价值。

刷刷水题

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int MOD = 10007;
const int N = 1e5+5;
bool notp[N];
int prime[N], pnum, mu[N];
int sum[N];
void Mobius() {
	memset(notp, 0, sizeof(notp));
	mu[1] = 1;
	for (int i = 2; i < N; i++) {
		if (!notp[i]) prime[++pnum] = i, mu[i] = -1;
		for (int j = 1; prime[j]*i < N; j++) {
			notp[prime[j]*i] = 1;
			if (i%prime[j] == 0) {
				mu[prime[j]*i] = 0;
				break;
			}
			mu[prime[j]*i] = -mu[i];
		}
	}
	sum[0] = 0;
	for (int i = 1; i < N; i++) sum[i] = sum[i-1] + mu[i];
}
LL Cal(int n, int m, int k)
{
    if (k == 0) return 0;
    if (n > m) swap(n, m);
    n /= k, m /= k;
    if (n == 0) return 0;
    LL ans = 0;
    int last;
    for (int i = 1; i <= n; i = last+1)
    {
        last = min(n/(n/i), m/(m/i));
        ans += (LL)(sum[last] - sum[i-1]) * ( (LL)(n/i)*(n/i-1)/2 + (n/i) + (LL)(m/i-n/i)*(n/i) );
    }
    return ans;
}
int t, a, b, c, d, k;
int main()
{
    Mobius();
    scanf("%d", &t);
    for (int tt = 1; tt <= t; tt++)
    {
        scanf("%d%d%d%d%d", &a, &b, &c, &d, &k);
        printf("Case %d: %lld\n", tt, Cal(b, d, k));
    }
}

  

以上是关于HDU 1695 - GCD的主要内容,如果未能解决你的问题,请参考以下文章

HDU 1695 GCD

hdu 1695 GCD 欧拉函数 + 容斥

HDU 1695 - GCD

GCD HDU - 1695 (欧拉 + 容斥)

GCD HDU - 1695

GCD HDU - 1695