标签:lan 思路 prim -- its include pre ofo tar
#include<bits/stdc++.h> using namespace std; #define ll long long #define maxn 123456 bool vis[maxn+10]; ll t,n,m,prime[maxn+10]; ll mu[maxn+10],ans,c; void getphi() { int cnt=0; mu[1]=1; for(int i=2; i<maxn; i++) { if(!vis[i]) { prime[++cnt]=i; mu[i]=-1; } for(int j=1; j<=cnt&&i*prime[j]<maxn; j++) { vis[i*prime[j]]=1; if(i%prime[j]==0) { mu[i*prime[j]]=0; break; } else mu[i*prime[j]]=-mu[i]; } } } int main() { getphi(); scanf("%lld",&t); while(t--) { ans=0; scanf("%lld%lld",&n,&m); c=min(n,m); for(int i=1; i<=c; i++) ans+=(ll)mu[i]*(n/i)*(m/i); printf("%lld\n",ans); } return 0; }
C - Visible Trees HDU - 2841 -莫比乌斯函数-容斥
标签:lan 思路 prim -- its include pre ofo tar
原文地址:https://www.cnblogs.com/SDUTNING/p/10261607.html