Möbius back to the naked question.
#include <iostream>#include<cstdio>#include<cstring>#include<cmath>#defineMAXN 50050using namespacestd;intN,a,b,d,pre[maxn],miu[maxn],prime[maxn],cnt=0;BOOLVIS[MAXN];voidmake_table () {miu[1]=1; for(intI=2; i<=maxn;i++) { if(vis[i]==false) {prime[++cnt]=i; Miu[i]=-1; } for(intj=1; j<=cnt && i*prime[j]<=maxn;j++) {vis[i*prime[j]]=true; if(i%prime[j]!=0) miu[i*prime[j]]=-Miu[i]; Else{miu[i*prime[j]]=0; Break; } } } for(intI=1; i<=maxn;i++) Pre[i]=pre[i-1]+miu[i];}intFindintAintBintd) { intI=1, ans=0; if(a>b) Swap (A, a); while(I<= (a)d)) {intJ; if(A/(i*d) = =0) || (b/(i*d) = =0)) j=0; ElseJ=min ((A/D)/((A/d)/i), (b/d)/((B/D)/i)); Ans+ = (pre[j]-pre[i-1]) * (A/(I*D)) * (b/(i*d)); I=j+1; } returnans;}voidWork () {scanf ("%d%d%d",&a,&b,&d); printf ("%d\n", find (A,b,d));}intMain () {scanf ("%d",&N); Make_table (); for(intI=1; i<=n;i++) work (); return 0;}
Bzoj 1101 Zap