Main topic:
The value of each position (I,J) in the table is the LCM (I,J), which is the size of the N*m table value.
This paper Jia Zhipeng the process of linear sieve is very good.
The last inverse of the equation, I'm using Euler's theorem.
I have this last linear sweep over, barely over, efficiency is not very high ...
1 /*Bzoj 2154*/2#include <bits/stdc++.h>3 4 using namespacestd;5 #definell Long Long6 #defineN 100000007 Const intMOD =20101009;8 intmu[n+5], prime[n+5], f[n+5], tot;9 BOOLcheck[n+5];Ten One voidInit () A { -mu[1] =1, f[1] =1; - for(intI=2; I<=n; i++){ the if(!Check[i]) { -prime[tot++] =i; -Mu[i] =-1; -F[i] =1-i; + } - for(intj=0; J<tot; J + +){ + if(LL) prime[j]*i>n) Break; ACheck[prime[j]*i] =true; at if(i%Prime[j]) { -Mu[prime[j]*i] =-Mu[i]; -F[prime[j]*i] = ((ll) f[prime[j]]*f[i])%MOD; -}Else{ -F[prime[j]*i] =F[i]; - Break; in } - } to } + } - the intQ_pow (intb) * { $ll ans =1, a=4;Panax Notoginseng while(b) - { the if(b&1) ans = (ans*a)%MOD; +A = (a*a)%MOD; Ab>>=1; the } + return(int) ans; - } $ $ intSolveintNintm) - { - if(n>m) Swap (n, m); theLL ret =0; - for(intk=1; K<=n; k++){Wuyill a = n/k, B = m/K; theret = (ret+ (k* (1+a)%mod) *a%mod*b%mod* (1+b)%mod*f[k]%mod)%MOD; - } Wuret = (ll) Ret*q_pow (mod-2)%mod+mod)%MOD; - return(int) ret; About } $ - intMain () - { - //freopen ("In.txt", "R", stdin); A init (); + intN, M; the /*for (int i=2; i<=100000; i++) - if (!check[i] && mod%i==0) cout<<i<< "yes" <<endl;*/ $ while(~SCANF ("%d%d", &n, &m)) { theprintf"%d\n", Solve (n, m)); the } the return 0; the}
Bzoj 2154 Inverse of the LCM and