# bzoj4407:于神之怒加强版

### 传送门

$ans=\sum_{i=1}^{n}\sum_{j=1}^{m}gcd(i,j)^k\\$

$f(d)=\sum_{i=1}^{n}\sum_{j=1}^{m}[gcd(i,j)==d]d^k\\ ans=\sum_{d=1}^{min(n,m)}f(d)=\sum_{d=1}^{min(n,m)}\sum_{i=1}^{n}\sum_{j=1}^{m}[gcd(i,j)==d]d^k\\ ans=\sum_{d=1}^{min(n,m)}d^k\sum_{i=1}^{n}\sum_{j=1}^{m}[gcd(i,j)==d]\\$

$F(d)=\sum_{i=1}^{n}\sum_{j=1}^{m}[gcd(i,j)==d]\\ g(x)=\sum_{x|d}F(d)=\sum_{i=1}^{n}\sum_{j=1}^{m}[x|gcd(i,j)]=\lfloor \frac{n}{x}\rfloor\lfloor \frac{m}{x}\rfloor\\ F(d)=\sum_{d|x}g(x)\mu(\frac{x}{d})=\sum_{d|x}\lfloor \frac{n}{x}\rfloor\lfloor \frac{m}{x}\rfloor\mu(\frac{x}{d})\\$

$T=\frac{x}{d}$

$F(d)=\sum_{T=1}^{min(n,m)/d}\lfloor \frac{n}{Td}\rfloor\lfloor \frac{m}{Td}\rfloor\mu(T)\\$

$ans=\sum_{d=1}^{min(n,m)}d^{k}F(d)\\ ans=\sum_{d=1}^{min(n,m)}d^{k}\sum_{T=1}^{min(n,m)/d}\lfloor \frac{n}{Td}\rfloor\lfloor \frac{m}{Td}\rfloor\mu(T)\\$

$ans=\sum_{k=1}^{min(n,m)}\lfloor \frac{n}{k}\rfloor\lfloor \frac{m}{k}\rfloor\sum_{d|k}\mu(\frac{k}{d})d^k$

$x$为质数时，除了$\mu(1)$以及$\mu(x)$不为$0$，其余都为$0$，那么$s(x)=\mu(1)*x^k+\mu(x)*1^k$

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
char ch; bool ok;
for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
#define rg register
const int maxn=5e6+10,mod=1e9+7;bool vis[maxn];
int T,k,n,m,pri[maxn],tot,ans,f[maxn],g[maxn];
int mi(int a,int b)
{
int ans=1;
while(b)
{
if(b&1)ans=1ll*ans*a%mod;
b>>=1,a=1ll*a*a%mod;
}
return ans;
}
void prepare()
{
f[1]=1;
for(rg int i=2;i<=5e6;i++)
{
if(!vis[i])pri[++tot]=i,g[i]=mi(i,k),f[i]=(g[i]-1+mod)%mod;
for(rg int j=1;pri[j]*i<=5e6&&j<=tot;j++)
{
vis[pri[j]*i]=1;
if(!(i%pri[j])){f[i*pri[j]]=1ll*f[i]*g[pri[j]]%mod;break;}
else f[i*pri[j]]=1ll*f[i]*f[pri[j]]%mod;
}
}
for(rg int i=1;i<=5e6;i++)f[i]=(f[i]+f[i-1])%mod;
}
int main()
{