Euler functions
Maya, I should take a look at Jzp's paper first. Jia Zhipeng "Linear sieve method and integrable function" example one
The practice of this problem ... Think carefully about what you can get: $ans =2*\sum_{a=1}^n\sum_{b=1}^m gcd (A, b)-n*m$
So the point is to Count $\sum_{a=1}^n\sum_{b=1}^m gcd (A, B) $ this thing
Copy the JZP derivation process:
$$ \sum_{a=1}^n \sum_{b=1}^m gcd (A, b) =&\sum_{a=1}^n \sum_{b=1}^m \sum_{d|gcd (A, B)} \varphi (d) $$
$$ = \sum_{a=1}^n \sum_{b=1}^m \sum_{d|a && d|b} \varphi (d) \ \ = \sum \varphi (d) \sum_{1 \leq a \leq n && D|a} \sum{1 \leq b \leq m && d|b} 1 \ = \sum \varphi (d) (\sum_{1 \leq a \leq n && d|a} 1) * (\SUM_{1 \l EQ b \leq m && d|b} 1) \ \ = \sum \varphi (d) \frac{n}{d} \frac{m}{d} \]
1 /**************************************************************2 problem:20053 User:tunix4 language:c++5 result:accepted6 time:40 Ms7 memory:2152 KB8 ****************************************************************/9 Ten //Bzoj 2005 One#include <cstdio> A#include <cstring> -#include <cstdlib> -#include <iostream> the#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) - #defineF (i,j,n) for (int i=j;i<=n;++i) - #defineD (i,j,n) for (int i=j;i>=n;--i) + using namespacestd; -typedefLong LongLL; +InlineintGetint () { A intR=1, v=0;CharCh=GetChar (); at for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') r=-1; - for(; isdigit (ch); Ch=getchar ()) v=v*Ten+ch-'0'; - returnr*v; - } - Const intn=1e5+Ten, inf=~0u>>2; - /*****************template**********************/ in intphi[n],prime[n],tot,n,m; - BOOLCheck[n]; to voidGetphi (intN) { +memset (check,0,sizeofcheck); -phi[1]=1; the inttot=0; *F (I,2, N) { $ if(!Check[i]) {Panax Notoginsengprime[++tot]=i; -phi[i]=i-1; the } +F (J,1, tot) { A if(i*prime[j]>n) Break; thecheck[i*prime[j]]=1; + if(i%prime[j]==0){ -phi[i*prime[j]]=phi[i]*Prime[j]; $ Break; $ } - Elsephi[i*prime[j]]=phi[i]* (prime[j]-1); - } the } - }Wuyi intMain () { theN=getint (); m=getint (); - if(n>m) swap (n,m); WuGetphi (n1); -LL ans=0; AboutF (I,1, N) $ans+= (LL) phi[i]* (n/i) * (m/i); -printf"%lld\n", ans*2-(LL) nm); - return 0; -}
View Code
"Bzoj" "2005" "NOI2010" energy harvesting