BZOJ 3309 DZY Loves Math
来源:互联网 发布:淘宝网百雀羚旗舰店 编辑:程序博客网 时间:2024/05/17 18:25
题目链接
题意
求
其中
推导
法一:艾弗森约定
记
故原式可化为
用莫比乌斯函数将艾弗森约定展开得
即
即
令
显然,接下来的路子就是求前缀和,然后分块计算,然而 关键问题 就是怎么求这个
参考PoPoQQQ可知,对于
有
具体证明见上附链接,要点为从
法二:莫比乌斯反演(待补)
Code
#include <bits/stdc++.h>#define maxn 10000000#define maxm maxn + 10using namespace std;typedef long long LL;bool check[maxm];int prime[maxm], cnt[maxm], val[maxm], g[maxm], sum[maxm];void init() { int tot = 0; g[1] = 0; for (int i = 2; i <= maxn; ++i) { if (!check[i]) { prime[tot++] = i; cnt[i] = 1, val[i] = i, g[i] = 1; } for (int j = 0; j < tot; ++j) { if (i * prime[j] > maxn) break; check[i * prime[j]] = true; if (i % prime[j] == 0) { cnt[i * prime[j]] = cnt[i] + 1, val[i * prime[j]] = val[i] * prime[j]; int temp = (i * prime[j]) / val[i * prime[j]]; if (temp == 1) g[i * prime[j]] = 1; else g[i * prime[j]] = (cnt[temp] == cnt[i * prime[j]] ? -g[temp] : 0); break; } cnt[i * prime[j]] = 1, val[i * prime[j]] = prime[j]; int temp = (i * prime[j]) / val[i * prime[j]]; if (temp == 1) g[i * prime[j]] = 1; else g[i * prime[j]] = (cnt[temp] == cnt[i * prime[j]] ? -g[temp] : 0); } } for (int i = 1; i <= maxn; ++i) sum[i] = sum[i - 1] + g[i];}void work() { LL a, b; scanf("%lld%lld", &a, &b); int le, ri, lim = min(a, b); LL ans = 0; for (int i = 1; i <= lim; i = ri + 1) { le = i, ri = min(a / (a / i), b / (b / i)); ans += (a / i) * (b / i) * (sum[ri] - sum[le - 1]); } printf("%lld\n", ans);}int main() { init(); int T; scanf("%d", &T); while (T--) work(); return 0;}
阅读全文
0 0
- bzoj 3309 DZY Loves Math
- DZY Loves Math [Bzoj 3309]
- BZOJ 3309: DZY Loves Math
- bzoj 3309: DZY Loves Math
- BZOJ 3309 DZY Loves Math
- 【线性筛】【bzoj 3309】: DZY Loves Math
- bzoj 3309: DZY Loves Math (反演)
- 3309: DZY Loves Math
- BZOJ 3309 DZY Loves Math 莫比乌斯反演
- bzoj 3309: DZY Loves Math 莫比乌斯反演
- BZOJ 3560 DZY Loves Math V 数论
- BZOJ 3560 DZY Loves Math V
- 【BZOJ 3560】DZY loves Math V
- BZOJ 3512: DZY Loves Math IV
- [杜教筛] BZOJ 3512 DZY Loves Math IV
- 【BZOJ 3560】【数论】DZY Loves Math V
- 【bzoj 3512】DZY loves math IV
- bzoj 3560 DZY Loves Math V
- 如何在JSP页面中使用JSTL标签实现if和if-else判断,判断条件使用<%=value%>
- pyqt5入门—001—绘制ui界面
- redis学习笔记
- 鸟哥的Nginx私房菜 哈哈哈 收藏学习
- 罗素说理想与历程
- BZOJ 3309 DZY Loves Math
- textview实现图片切换效果
- 解决win10等系统修复windows键失灵 不弹出开始菜单问题
- Hello Activiti 创建工作流的三种方式
- keras中文文档笔记3——常见问题与解答
- Linux系统apache服务
- Linux系统samba服务
- mysql安装出现error Nr.1045
- 用java语句来查找数据库中的数据