CodeForces 235 E.Number Challenge（莫比乌斯反演+数论）

Description

i=1aj=1bk=1cd(ijk),a,b,c2000 $\sum\limits_{i=1}^a\sum\limits_{j=1}^b\sum\limits_{k=1}^cd(ijk),a,b,c\le 2000$

Input

Output

Sample Input

2 2 2

Sample Output

20

Solution

1 $1$.d(mn)=i|mj|n[(i,j)=1]$d(mn)=\sum\limits_{i|m}\sum\limits_{j|n}[(i,j)=1]$

m=pa11pa22...paxx,n=pb11pb22...pbxx $m=p_1^{a_1}p_2^{a_2}...p_x^{a_x},n=p_1^{b_1}p_2^{b_2}...p_x^{b_x}$

mn $mn$的任一正因子 l $l$，假设l=pc11pc22...pcxx$l=p_1^{c_1}p_2^{c_2}...p_x^{c_x}$，则有 0ciai+bi $0\le c_i\le a_i+b_i$

s=pd11pd22...pdxx $s=p_1^{d_1}p_2^{d_2}...p_x^{d_x}$ t=pe11pe22...pexx $t=p_1^{e_1}p_2^{e_2}...p_x^{e_x}$，其中 di={ci0ciaici>ai $d_i=\left\{\begin{array}{rcl}c_i & c_i\le a_i\\0&c_i>a_i\end{array}\right.$ ei={0ciaiciaici>ai $e_i=\left\{\begin{array}{lcl}0 & c_i\le a_i\\c_i-a_i&c_i>a_i\end{array}\right.$

2 $2$.d(rst)=i|rj|sk|t[(i,j)=1][(i,k)=1][(j,k)=1]$d(rst)=\sum\limits_{i|r}\sum\limits_{j|s}\sum\limits_{k|t}[(i,j)=1][(i,k)=1][(j,k)=1]$

d(rst)=i|rj|st[(i,j)=1]=i|sj|sk|t[(i,jk)=1][(j,k)=1]=i|rj|sk|t[(i,j)=1][(i,k)=1][(j,k)=1] $d(rst)=\sum\limits_{i|r}\sum\limits_{j|st}[(i,j)=1]=\sum\limits_{i|s}\sum\limits_{j|s}\sum\limits_{k|t}[(i,jk)=1][(j,k)=1]=\sum\limits_{i|r}\sum\limits_{j|s}\sum\limits_{k|t}[(i,j)=1][(i,k)=1][(j,k)=1]$

i=1aj=1bk=1cd(ijk) ====r=1as=1bt=1ci|rj|sk|t[(i,j)=1][(i,k)=1][(j,k)=1]i=1aj=1bk=1caibjck[(i,j)=1][(i,k)=1][(j,k)=1]i=1aj=1bk=1caibjck[(i,j)=1][(i,k)=1]d|(j,k)μ(d)i=1aaid=1min(b,c)μ(d)j=1bdbjd[(i,jd)=1]k=1cdckd[(i,kd)=1]

Code

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=2005;
#define mod 1073741824
int gcd[maxn][maxn],mu[maxn],p[maxn],vis[maxn],res;
void init(int n=2000)
{
res=0;
mu[1]=1;
for(int i=2;i<=n;i++)
{
if(!vis[i])p[res++]=i,mu[i]=-1;
for(int j=0;j<res&&i*p[j]<=n;j++)
{
vis[i*p[j]]=1;
if(i%p[j])mu[i*p[j]]=-mu[i];
else
{
mu[i*p[j]]=0;
break;
}
}
}
for(int i=0;i<=n;i++)gcd[i][0]=gcd[0][i]=i;
for(int i=1;i<=n;i++)
for(int j=1;j<=i;j++)
gcd[j][i]=gcd[i][j]=gcd[j][i%j];
}
int deal(int n,int d,int i)
{
int ans=0;
for(int j=1;j<=n;j++)
if(gcd[i][j*d]==1)ans+=n/j;
return ans;
}
int main()
{
init();
int a,b,c;
while(~scanf("%d%d%d",&a,&b,&c))
{
int ans=0;
for(int i=1;i<=a;i++)
{
int res=0;
for(int d=1;d<=min(b,c);d++)
{
res+=((ll)mu[d]*deal(b/d,d,i)*deal(c/d,d,i)%mod+mod)%mod;
if(res>=mod)res-=mod;
}
ans+=(ll)(a/i)*res%mod;
if(ans>=mod)ans-=mod;
}
printf("%d\n",ans);
}
return 0;
}


07-04 1218
10-28 490
06-18 1776
03-14 34
05-09 1016
07-29 33
11-19 398
04-07 2089
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客