标签:sof scanf stream string 解释 条件 ... return content
对于100%的数据满足0 < A, B < 10^ 6
题解:
总之就是一旦看到[...=1]就往反演上想就好了
#include <cstdio> #include <cstring> #include <iostream> using namespace std; const int maxn=1000010; int n,m,d,num; int pri[maxn],mu[maxn],sm[maxn]; bool np[maxn]; typedef long long ll; ll ans; int main() { scanf("%d%d%d",&n,&m,&d),n/=d,m/=d; if(n<m) swap(n,m); int i,j,last; sm[1]=mu[1]=1; for(i=2;i<=n;i++) { if(!np[i]) pri[++num]=i,mu[i]=-1; sm[i]=sm[i-1]+mu[i]; for(j=1;j<=num&&i*pri[j]<=n;j++) { np[i*pri[j]]=1; if(i%pri[j]==0) { mu[i*pri[j]]=0; break; } mu[i*pri[j]]=-mu[i]; } } for(i=1;i<=m;i=last+1) { last=min(n/(n/i),m/(m/i)); ans+=1ll*(sm[last]-sm[i-1])*(n/i)*(m/i); } printf("%lld",ans); return 0; }
标签:sof scanf stream string 解释 条件 ... return content
原文地址:http://www.cnblogs.com/CQzhangyu/p/6999154.html