51nod 1244 莫比乌斯函数之和 【莫比乌斯函数+杜教筛】
和bzoj 3944比较像,但是时间卡的更死
设\( f(n)=\sum_{d|n}\mu(d) g(n)=\sum_{i=1}^{n}f(i) s(n)=\sum_{i=1}^{n}\mu(i) \),然后很显然对于mu\( g(n)=1\),对于\( g(n)=n*(n+1)/2 \),然后可以这样转化一下:
\]
\]
\]
\]
然后递归求解即可。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const long long N=5000005,m=4500000;
long long mb[N],tot,q[N],p[N];
long long l,r;
bool v[N];
long long getp(long long x,long long n)
{
return (x<=m)?mb[x]:p[n/x];
}
void slv(long long x,long long n)
{
if(x<=m)
return;
long long t=n/x;
if(v[t])
return;
v[t]=1;
p[t]=1;
for(long long i=2,la;la<x;i=la+1)
{
la=x/(x/i);
slv(x/i,n);
p[t]-=getp(x/i,n)*(la-i+1);
}
}
long long wk(long long n)
{
if(n<=m)
return mb[n];
memset(v,0,sizeof(v));
slv(n,n);
return p[1];
}
int main()
{
mb[1]=1;
for(long long i=2;i<=m;i++)
{
if(!v[i])
{
q[++tot]=i;
mb[i]=-1;
}
for(long long j=1;j<=tot&&i*q[j]<=m;j++)
{
long long k=i*q[j];
v[k]=1;
if(i%q[j]==0)
{
mb[k]=0;
break;
}
mb[k]=-mb[i];
}
}
for(long long i=1;i<=m;i++)
mb[i]+=mb[i-1];
scanf("%lld%lld",&l,&r);
printf("%lld\n",wk(r)-wk(l-1));
return 0;
}
51nod 1244 莫比乌斯函数之和 【莫比乌斯函数+杜教筛】的更多相关文章
- 51nod 1237 最大公约数之和 V3(杜教筛)
[题目链接] https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1237 [题目大意] 求[1,n][1,n]最大公约数之和 ...
- 【luogu3768】简单的数学题 欧拉函数(欧拉反演)+杜教筛
题目描述 给出 $n$ 和 $p$ ,求 $(\sum\limits_{i=1}^n\sum\limits_{j=1}^nij\gcd(i,j))\mod p$ . $n\le 10^{10}$ . ...
- Wannafly Camp 2020 Day 3D 求和 - 莫比乌斯反演,整除分块,STL,杜教筛
杜教筛求 \(\phi(n)\), \[ S(n)=n(n+1)/2-\sum_{d=2}^n S(\frac{n}{d}) \] 答案为 \[ \sum_{d=1}^n \phi(d) h(\fra ...
- [51nod1237] 最大公约数之和 V3(杜教筛)
题面 传送门 题解 我好像做过这题-- \[ \begin{align} ans &=\sum_{i=1}^n\sum_{j=1}^n\gcd(i,j)\\ &=\sum_{d=1}^ ...
- [51nod1238] 最小公倍数之和 V3(杜教筛)
题面 传送门 题解 懒了--这里写得挺好的-- //minamoto #include<bits/stdc++.h> #define R register #define ll long ...
- 51nod 1244 莫比乌斯函数之和 【杜教筛】
51nod 1244 莫比乌斯函数之和 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens)首先使用μ(n)(miu(n))作为莫比乌斯函数的记号.具体定义如下: 如果一个数包含 ...
- 51nod 1244 莫比乌斯函数之和(杜教筛)
[题目链接] http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 [题目大意] 计算莫比乌斯函数的区段和 [题解] 利 ...
- 51Nod.1244.莫比乌斯函数之和(杜教筛)
题目链接 map: //杜教筛 #include<map> #include<cstdio> typedef long long LL; const int N=5e6; in ...
- 【51nod-1239&1244】欧拉函数之和&莫比乌斯函数之和 杜教筛
题目链接: 1239:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1239 1244:http://www.51nod. ...
- 51 NOD 1244 莫比乌斯函数之和(杜教筛)
1244 莫比乌斯函数之和 基准时间限制:3 秒 空间限制:131072 KB 分值: 320 难度:7级算法题 收藏 关注 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens) ...
随机推荐
- APP后端处理表情的一些技巧
app应用中文字夹带表情是个很常见的现象.甚至一些40多岁的大叔级用户,也喜欢在自己的昵称中夹带表情,在产品运营后发现这个现象,彻底颠覆了我的世界观. 在后台处理表情的时间,我遇到过下面3个问题: 1 ...
- HDU 1074 Doing Homework【状态压缩DP】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题意: 给定作业截止时间和完成作业所需时间,比截止时间晚一天扣一分,问如何安排作业的顺序使得最 ...
- struts2常用类型的Result
2.2.1. dispatcher dispatcher类型是用于转发的Result,可以将请求转发给JSP.这种类型的Result对应的类为 ServletDispatcherResult,它是St ...
- POJ 3281 [网络流dinic算法模板]
题意: 农场主有f种食物,d种饮料,n头牛. 接下来的n行每行第一个数代表第i头牛喜欢吃的食物数量,和第i头牛喜欢喝的饮料数目. 接下来分别是喜欢的食物和饮料的编号. 求解:农场主最多能保证几头牛同时 ...
- 怎么配置ODBC microsoft Access 安装(win10)
笔者看着书配置Access连接方法但就是找不到书中的"Access.mdb". 后来才知道.mdb需要自己创建....对于刚入门的我很无语啊!!!!! 下面带你走出小坑 1.从控制 ...
- Unable to process request: General SSLEngine problem.Unable to connect to neo4j at `localhost:7687`, because the certificate the server uses has changed.
Exception in thread "main" org.neo4j.driver.v1.exceptions.ClientException: Unable to proce ...
- 关于oracle存储过程的若干问题备忘
1.在oracle中,数据表别名不能加as,如: select a.appname from appinfo a;-- 正确select a.appname from appinfo as a;-- ...
- dhcp 过程
The Question SuperUser reader Sagnik Sarkar wants to know what the difference between 127.0.0.1 and ...
- Android - 隐藏EditText弹出的软键盘输入(SoftInput)
隐藏EditText弹出的软键盘输入(SoftInput) 本文地址: http://blog.csdn.net/caroline_wendy 保持界面的整洁, 能够选择在进入界面时, 隐藏EditT ...
- PHP根据两点间的经纬度计算距离
/** * 说明: 根据两点间的经纬度计算距离 * @param float $lat 纬度值 * @param float $lng 经度值 */ function getDistance($lat ...