传送门

Sol

好神仙的题目。。

一开始就直接莫比乌斯反演然后就 \(GG\) 了

orz 题解

permui

枚举 \(n\),就是求 \(\sum_{i=1}^{n}S(i,m)\)

其中\(S(n,m)=\sum _{i=1}^m\varphi (ni)\)

设 \(n=\prod_{i}p_i^{c_i}\)

设 \(y=\prod _{i=1} p_i^{c_i-1}\),\(w=\prod _{i=1}p_j\)

那么

\[\begin{aligned}
S(n,m)&=y\sum _{i=1}^m\varphi (wi) \\
&=y\sum _{i=1}^m\varphi (\frac{w}{gcd(i,w)})\varphi (i)gcd(i,w) \\
&=y\sum _{i=1}^m\varphi (\frac{w}{gcd(i,w)})\varphi (i)\sum _{e|gcd(i,w)}\varphi (e) \\
&=y\sum _{i=1}^m\varphi (i)\sum _{e|gcd(i,w)}\varphi (\frac{w}{e}) \\
&=y\sum _{i=1}^m\varphi (i)\sum _{e|i,e|w}\varphi (\frac{w}{e}) \\
&=y\sum _{e|w} \varphi (\frac{w}{e})S(e,\lfloor\frac{m}{e}\rfloor) \\
\end{aligned}
\]

运用了 \(n=\sum _{d|n}\varphi (d)\) 去掉了 \(gcd\)

# include <bits/stdc++.h>
using namespace std;
typedef long long ll; const int mod(1e9 + 7);
const int maxn(1e6 + 5);
const int blk(80); inline void Inc(int &x, int y) {
if ((x += y) >= mod) x -= mod;
} int pr[maxn], phi[maxn], tot, d, id1[maxn], id2[maxn], idx, m, ans, sphi[maxn], low[maxn];
bitset <maxn> ispr;
map <int, int> s[maxn]; # define ID(x) ((x) <= d ? id1[x] : id2[m / (x)]) int Sumphi(int x) {
if (x < maxn) return phi[x];
if (sphi[ID(x)]) return sphi[ID(x)];
register int ans = (ll)(x + 1) * x / 2 % mod, i, j;
for (i = 2; i <= x; i = j + 1) j = x / (x / i), Inc(ans, mod - (ll)Sumphi(x / i) * (j - i + 1) % mod);
return sphi[ID(x)] = ans;
} int Calc(int n, int v) {
if (!v || !n) return 0;
if (n == 1) return Sumphi(v);
if (v == 1) return (phi[n] - phi[n - 1] + mod) % mod;
if (s[n].count(v)) return s[n][v];
register int i, j, ret, y = 1, w = 1, x, cnt, e, dv[30];
for (cnt = 0, x = n; x > 1; ) {
w *= low[x], dv[++cnt] = low[x], x /= low[x];
while (low[x] == dv[cnt]) y *= low[x], x /= low[x];
}
for (ret = 0, i = (1 << cnt) - 1; ~i; --i) {
for (e = 1, j = 0; j < cnt; ++j) if (i >> j & 1) e *= dv[j + 1];
Inc(ret, (ll)(phi[w / e] - phi[w / e - 1] + mod) * Calc(e, v / e) % mod);
}
return s[n][v] = (ll)ret * y % mod;
} int main() {
register int i, j, n;
phi[1] = 1, ispr[1] = 1;
for (i = 2; i < maxn; ++i) {
if (!ispr[i]) pr[++tot] = i, phi[i] = i - 1, low[i] = i;
for (j = 1; j <= tot && i * pr[j] < maxn; ++j) {
ispr[i * pr[j]] = 1;
if (i % pr[j]) phi[i * pr[j]] = phi[i] * (pr[j] - 1), low[i * pr[j]] = pr[j];
else {
phi[i * pr[j]] = phi[i] * pr[j], low[i * pr[j]] = low[i];
break;
}
}
}
for (i = 1; i < maxn; ++i) Inc(phi[i], phi[i - 1]);
scanf("%d%d", &n, &m);
for (d = sqrt(m), i = 1; i <= m; i = j + 1) {
j = m / (m / i);
(m / i <= d) ? id1[m / i] = ++idx : id2[j] = ++idx;
}
for (i = 1; i <= n; ++i) Inc(ans, Calc(i, m));
printf("%d\n", ans);
return 0;
}

BZOJ3512:DZY Loves Math IV的更多相关文章

  1. 【BZOJ3512】DZY Loves Math IV(杜教筛)

    [BZOJ3512]DZY Loves Math IV(杜教筛) 题面 BZOJ 求 \[\sum_{i=1}^n\sum_{j=1}^m\varphi(ij)\] 其中\(n\le 10^5,m\l ...

  2. 【bzoj3512】DZY Loves Math IV 杜教筛+记忆化搜索+欧拉函数

    Description 给定n,m,求\(\sum_{i=1}^{n}\sum_{j=1}^{m}\varphi(ij)\)模10^9+7的值. Input 仅一行,两个整数n,m. Output 仅 ...

  3. BZOJ 3512: DZY Loves Math IV [杜教筛]

    3512: DZY Loves Math IV 题意:求\(\sum_{i=1}^n \sum_{j=1}^m \varphi(ij)\),\(n \le 10^5, m \le 10^9\) n较小 ...

  4. BZOJ3512 DZY Loves Math IV

    解:这又是什么神仙毒瘤题...... 我直接把后面那个phi用phi * I = id反演一波,得到个式子,然后推不动了...... 实际上第一步我就大错特错了.考虑到n很小,我们有 然后计算S,我们 ...

  5. BZOJ3512 DZY Loves Math IV(杜教筛+线性筛)

    注意到n很小,考虑枚举i.现在要求的是f(n,m)=Σφ(in) (i=1~m).显然当n没有平方因子时,φ(in)=φ(i)·φ(n/gcd(i,n))·gcd(i,n).利用φ*1=id又可得φ( ...

  6. 数学(数论)BZOJ 3309:DZY Loves Math

    Description 对于正整数n,定义f(n)为n所含质因子的最大幂指数.例如f(1960)=f(2^3 * 5^1 * 7^2)=3, f(10007)=1, f(1)=0. 给定正整数a,b, ...

  7. ●BZOJ 3512 DZY Loves Math IV

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3512 题解: $$求ANS=\sum_{i=1}^{N}\sum_{j=1}^{M}\phi ...

  8. 【刷题】BZOJ 3512 DZY Loves Math IV

    Description 给定n,m,求 模10^9+7的值. Input 仅一行,两个整数n,m. Output 仅一行答案. Sample Input 100000 1000000000 Sampl ...

  9. bzoj 3512: DZY Loves Math IV【欧拉函数+莫比乌斯函数+杜教筛】

    参考:http://blog.csdn.net/wzf_2000/article/details/54630931 有这样一个显然的结论:当\( |\mu(n)|==1 \)时,\( \phi(nk) ...

随机推荐

  1. Python3之urllib模块

    简介 urllib是python的一个获取url(Uniform Resource Locators,统一资源定位符),可以用来抓取远程的数据. 常用方法 (1)urlopen urllib.requ ...

  2. 网络请求及各类错误代码含义总结(包含AFN错误码大全)

    碰见一个很奇葩的问题, 某些手机在设置了不知什么后, 某些 APP 死活 HTTPS 请求失败, 例如以 UMeng 统计HTTP 请求失败为例, Log如下: UMLOG: (Error   App ...

  3. CentOS 7 安装程序介绍

    (一).引导菜单 使用 UEFI 引导 Install CentOS Linux 7 选择此选项开始在你的计算机系统中使用图形安装程序安装 CentOS 7 Test this media & ...

  4. CentOS 7下安装RabbitMQ

    下载erlang:http://www.erlang.org/downloads ,otp_src_20.3.tar.gz 下载RabbitMQ: http://www.rabbitmq.com ,r ...

  5. Mac下常用快捷键(转)

    前提,先熟读键盘快捷键符号:http://www.cnblogs.com/EasonJim/p/6350075.html 基本操作: Command-Z 撤销 Command-X 剪切 Command ...

  6. WCF系列教程之WCF服务宿主与WCF服务部署

    本文参考自http://www.cnblogs.com/wangweimutou/p/4377062.html,纯属读书笔记,加深记忆. 一.简介 任何一个程序的运行都需要依赖一个确定的进程中,WCF ...

  7. utf8 和 UTF-8 在使用中的区别

    在使用中常常遇到utf-8和utf8,现在终于弄明白他们的使用不同之处了,现在来和大家分享一下,下面我们看一下utf8 和 UTF-8 有什么区别 “UTF-8”是标准写法,php在Windows下边 ...

  8. shell脚本杀进程重启

    #!/bin/bash ID=`ps -ef | grep "abc" | grep -v "$0" | grep -v "grep" | ...

  9. 21.Decorator修饰器

    1.类的修饰 2.方法的修饰 3.为什么修饰器不能用于函数? 4.core-decorators.js 5.使用修饰器实现自动发布事件 6.Mixin 7.Trait 8.Babel转码器的支持

  10. JS中typeof和instanceof的用法和区别

    typeof和instanceof的区别 instanceof 常用来判断一个变量是否为空,或者是什么类型的.但它们之间还是有区别的 instanceof的用法 instanceof返回的是一个布尔值 ...