"The main topic"
For a given integer, a, B, and D, how many positive integers to X, y, meet X<=a,y<=b, and gcd (x, y) =d.
Ideas
The idea of the front with HDU1695
However, the difference is that the problem (a, B) and (B,a) count as the same situation, do not need to subtract from the duplication of the situation.
This problem uses chunking to speed up efficiency. We can notice that the same, B ' (b '/i) B means the same as the current quotient of the last [B '/d],d ' (d '/i), POS is the smaller of the two. We preprocess Miu's prefix and can be the same as * (Sum[pos]-pos[k-1])!
?? Bzoj must use Printf%lld,cout will re??
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6typedefLong Longll;7 Const intmaxn=50000+ -;8 Const intinf=0x7ffffff;9 inta,b,d;Ten intMIU[MAXN]; One intMIU_SUM[MAXN]; A - voidGet_miu (intMAXN) - { the intprime[maxn],pnum=0; -memset (Miu_sum,0,sizeof(Miu_sum)); -miu[1]=miu_sum[1]=1; - for(intI=2; i<maxn;i++) miu[i]=-INF; + for(intI=2; i<maxn;i++) - { + if(miu[i]==-INF) A { atmiu[i]=-1; -prime[++pnum]=i; - } - for(intj=1; j<=pnum;j++) - { - if(I*PRIME[J]>=MAXN) Break; in if(i%prime[j]==0) miu[i*prime[j]]=0; - Elsemiu[i*prime[j]]=-Miu[i]; to } +miu_sum[i]=miu_sum[i-1]+Miu[i]; - } the } * $ll Get_ans (intAintBintd)Panax Notoginseng { - intub=min (A, b), POS; thell ans=0; + for(intI=1; i<=ub;i=pos+1) A { thePos=min (A/(a/i), b/i)); +ans+= (LL) (miu_sum[pos]-miu_sum[i-1]) * (a/i) * (b/i); - } $ returnans; $ } - - intMain () the { - intT;Wuyiscanf"%d",&T); theGet_miu (maxn-1); - for(intI=0; i<t;i++) Wu { -scanf"%d%d%d",&a,&b,&d); AboutA/=d;b/=D; $printf"%lld\n", Get_ans (a,b,d)); - } -}
"Bzoj1101-[poi2007]zap inversion + chunking"