标签:void space cpp long ret pac mob amp lld
刷刷水题
#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)); } }
标签:void space cpp long ret pac mob amp lld
原文地址:http://www.cnblogs.com/nicetomeetu/p/7362084.html