Statement
\(f(x)\) 表示 \(x\) 所含质因子的最大幂指数,对于 \(T=10^4\),\(a,b\le10^7\),求
\[ \sum_{i=1}^a\sum_{j=1}^bf(\gcd(i,j)) \]时限 2s
Solution
\[ \begin{aligned} &\sum_{i=1}^a\sum_{j=1}^bf(\gcd(i,j))\\ =&\sum_{i=1}^a\sum_{j=1}^b\sum_{d=1}^{\min(a,b)}[d=\gcd(i,j)]f(d)\\ =&\sum_{d=1}^{\min(a,b)}f(d)\sum_{i=1}^a\sum_{j=1}^b[\gcd(i,j)=d]\\ =&\sum_{d=1}^{\min(a,b)}f(d)\sum_{i=1}^{\left\lfloor\frac ad\right\rfloor}\sum_{j=1}^{\left\lfloor\frac bd\right\rfloor}[\gcd(i,j)=1]\\ =&\sum_{d=1}^{\min(a,b)}f(d)\sum_{i=1}^{\left\lfloor\frac ad\right\rfloor}\sum_{j=1}^{\left\lfloor\frac bd\right\rfloor}\sum_{p\mid i\land p\mid j}\mu(p)\\ =&\sum_{d=1}^{\min(a,b)}f(d)\sum_{p=1}^{\min(\left\lfloor\frac ad\right\rfloor,\left\lfloor\frac bd\right\rfloor)}\mu(p)\left\lfloor\dfrac a{dp}\right\rfloor\left\lfloor\dfrac b{dp}\right\rfloor\\ =&\sum_{d=1}^{\min(a,b)}\sum_{p=1}^{\min(\left\lfloor\frac ad\right\rfloor,\left\lfloor\frac bd\right\rfloor)}f(d)\mu(p)\left\lfloor\dfrac a{dp}\right\rfloor\left\lfloor\dfrac b{dp}\right\rfloor\\ =&\sum_{k=1}^{\min(a,b)}\left\lfloor\dfrac ak\right\rfloor\left\lfloor\dfrac bk\right\rfloor\sum_{d\mid k}f(d)\mu\left(\frac kd\right) \end{aligned} \]记 \(g(k)=\sum_{d\mid k}f(d)\mu(\frac kd)\),这就是后面一个 Sigma
若预处理出 \(g\) 的前缀和,这个式子就可以数论分块求
以上是自己想出的,属于基操。
1
因为对于 \(\gcd(x,y)=1\),有 \(f(xy)=\max(f(x),f(y))\)、\(\mu(xy)=\mu(x)\mu(y)\),我们觉得 \(g\) 没有积性,不好求
而 \(g(n)=\sum_{ab=n}f(a)\mu(b)\)
求完 \(f,\mu\) 后直接:
for (int b = 1; b <= n; ++b) if (mu[b]) for (int a = b; a <= n; a += b) g[a] += mu[b] * f[a / b];
经过实践这个计算量是 1e8 的,可以接受
为什么不是直接 \(n\ln n\) 的呢?因为只用到了 \(\mu(i)\not=0\) 的部分,这样的 \(i\) 只有 6e6 个
2
sto hunction orz
我们还是推一下 \(g\) 怎么求:
\[ g(p^\alpha)=f(p^\alpha)-f(p^{\alpha-1})=1 \]而剩余 \(n=p_1^{\alpha_1}p_2^{\alpha_2}...\),当 \(\alpha_1=\alpha_2=\alpha_3=\cdots\) 时,
除了 \(\mu(p_1p_2p_3\cdots)f\left(\frac t{p_1p_2p_3\cdots}\right)=\alpha_1-1\) 之外,其他都是 \(\alpha_1\)
故 \(g(n)=(-1)^{m+1}\)
而 \(\alpha\) 不相等时易证 \(g(n)=0\)
标签:lfloor,mu,right,最大,题解,sum,rfloor,幂指数,left From: https://www.cnblogs.com/laijinyi/p/18148390