分析
推式子题。
\[ans=\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}\tau(i)\tau(j)\tau(\gcd(i,j)) \]对于 \((i,j)\),若 \(k\) 是 \((i,j)\) 的因子,则 \(k\) 一定整除 \(i,j\),所以有:
\[\\ \sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}\tau(i)\tau(j)\sum\limits_{k|i \land k|j} 1\]把 \(k\) 提到外面去枚举:
\[\\ \sum\limits_{k=1}^{\min(n,m)}\sum\limits_{k|i}^{n}\sum\limits_{k|j}^{m}\tau(i)\tau(j)\]发现每个 \(j\) 都有 \(\tau(i)\),提出来:
\[\\ \sum\limits_{k=1}^{\min(n,m)}\sum\limits_{k|i}^{n}\tau(i)\sum\limits_{k|j}^{m}\tau(j)\]然后就有:
\[\\ \sum\limits_{k=1}^{\min(n,m)}(\sum\limits_{k|i}^{n}\tau(i)) \times (\sum\limits_{k|j}^{m}\tau(j))\]在枚举 \(k\) 的时候可以通过暴力求出来 \(\sum\limits_{k|i}^{n}\tau(i)\) 和 \(\sum\limits_{k|j}^{m}\tau(j)\),\(\tau(x)\) 预处理就行了。复杂度 \(O(n \ln n)\)。
代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define re register
#define il inline
#define pii pair<int,int>
#define x first
#define y second
#define gc getchar()
#define rd read()
#define debug() puts("------------")
namespace yzqwq{
il int read(){
int x=0,f=1;char ch=gc;
while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=gc;}
while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=gc;
return x*f;
}
il int qmi(int a,int b,int p){
int ans=1;
while(b){
if(b&1) ans=ans*a%p;
a=a*a%p,b>>=1;
}
return ans;
}
il auto max(auto a,auto b){return (a>b?a:b);}
il auto min(auto a,auto b){return (a<b?a:b);}
il int gcd(int a,int b){
if(!b) return a;
return gcd(b,a%b);
}
il int lcm(int a,int b){
return a/gcd(a,b)*b;
}
il void exgcd(int a,int b,int &x,int &y){
if(!b) return x=1,y=0,void(0);
exgcd(b,a%b,x,y);
int t=x;
x=y,y=t-a/b*x;
return ;
}
mt19937 rnd(time(0));
}
using namespace yzqwq;
const int N=2e6+10;
int n,m,p;
int s[N];
il void solve(){
for(re int i=1;i<N;++i)
for(re int j=1;j*i<N;++j)
++s[i*j];
n=rd,m=rd,p=rd;
int ans=0;
for(re int k=1;k<=min(n,m);++k){
int s1=0,s2=0;
for(re int w=1;w*k<=n;++w) s1=(s1+s[w*k])%p;
for(re int w=1;w*k<=m;++w) s2=(s2+s[w*k])%p;
ans=(ans+s1*s2%p)%p;
}
printf("%lld\n",ans);
return ;
}
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int t=1;while(t--)
solve();
return 0;
}
标签:02,tau,ch,MCOI,limits,题解,sum,auto,define
From: https://www.cnblogs.com/harmisyz/p/18061652