标签:def namespace name scanf names print 复杂度 ons 利用
#include <bits/stdc++.h> using namespace std; const int mx = 1e5+5; typedef long long ll; bool vis[mx]; int sum[mx], prim[mx], mu[mx], cnt = 0; void get_mu(){ mu[1] = 1; for(int i = 2; i< mx; i++){ if(!vis[i]) { prim[++cnt] = i; mu[i] = -1; } for(int j = 1; j <= cnt && prim[j]*i < mx; j++) { vis[prim[j]*i] = 1; if(i % prim[j] == 0) break; else mu[i*prim[j]] = -mu[i]; } } sum[0] = 0; for (int i = 0; i < mx; i++) sum[i] = sum[i-1]+ mu[i]; } int main() { get_mu(); int n, m; scanf("%d%d", &n, &m); int len = min(n, m); int last; ll ans = 0; /*利用n/i连续区间数值相同的性质进行分块计算,可把复杂度降为sqrt(n) */ for (int i = 1; i <= len; i=last+1) { last = min(n/(n/i), m/(m/i)); ans += 1LL * (sum[last] - sum[i-1]) * (n/i) * (m/i); } printf("%lld\n", ans); }
标签:def namespace name scanf names print 复杂度 ons 利用
原文地址:https://www.cnblogs.com/bpdwn-cnblogs/p/11197113.html