Analysis: http://www.cnblogs.com/huhuuu/archive/2011/11/25/2263803.html
Note: Two points have been harvested from this question
1, the number of the hour on the first quadrant (x, y) to (0,0) line is gcd (x, y)
2, the newly learned gcd (x, y) =k How many pairs of posture, known 0<x<=n,0<y<=m
Make X=min (n,m), so f[i] represents the logarithm of gcd (x, y) =i,
Then the complexity of O (XLOGX) can be obtained f[1] to F[n] (reverse loop)
Ordinary Möbius (ie, inversion) is actually O (XLOGX), just need to sift through the Möbius function
Summary: For a single gcd (x, y) =k logarithm, can be done with Möbius inversion, such complexity is O (n/k)
For gcd (x, y) = (1,.. n) logarithm, each solved separately, directly with such O (NLOGN) sieve method is good, save code, fortunately write
#include <cstdio>#include<cstring>#include<queue>#include<cstdlib>#include<algorithm>#include<vector>#include<cmath>using namespaceStd;typedefLong LongLL;Const intn=1e5+5;Const intinf=0x3f3f3f3f; LL F[n];intMain () {LL N,m,ans=0; scanf ("%lld%lld",&n,&m); if(n>m) swap (N,M); for(inti=n;i>=1;--i) {F[i]=n/i* (m/i); for(intj=i+i;j<=n;j+=i) f[i]-=F[j]; Ans+=f[i]* (2*i-1); } printf ("%lld\n", ans); return 0;}
View Code
BZOJ2005: [Noi2010] Another method of energy harvesting for the inverse of the--nlogn sieve