P6810

\[\large 求\sum_{i=1}^n\sum_{j=1}^mg(i)*g(j)*g(gcd(i,j))~~~~~~~\{g为约数个数\} \]

\[\large\sum_{i\le n}\sum_{j\le m}g(i)g(j)\sum_{k|i,k|j}1\\ \large\sum_k\sum_{k|i,i\le n}g(i)\sum_{k|j,j\le m}g(j)\\ \large令S_n(k)=\sum_{k|i,i\le n}g(i)\\ \large原式=\sum_kS_n(k)S_m(k) \]

void shai(int n){
	for(int i = 1;i <= n;++i)
		for(int j = i;j <= n;j += i)
			++g[j];
}
inline int calc(int n,int k){
	int res = 0;
	for(int i = k;i <= n;i += k) res = (res + g[i]) % p;
	return res;
}
int main(){
	scanf("%d%d%d",&n,&m,&p);
	if(n > m) swap(n,m);
	shai(m);
	for(int i = 1;i <= n;++i) ans = (ans+1ll*calc(n,i)*calc(m,i)%p) % p;
	printf("%d",ans);
}
posted @ 2020-10-13 16:32  INFP  阅读(86)  评论(0编辑  收藏  举报