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) ...
随机推荐
- iOS url带中文下载时 报错解决方法
问题描述:下载文件时, 请求带中文的URL的资源时,比如:http://s237.sznews.com/pic/2010/11/23/e4fa5794926548ac953a8a525a23b6f2/ ...
- Object_C 定义全局宏的颜色时,报“Expected identifier”的错误
在定义全局颜色宏的时候,为了整齐把空格删了,写在了同一行里,调用的时候,出错提示“Expected identifier”,如下: 如果宏定义如上那样的话,在调用的时候,会出现如下的问题: 百思不得解 ...
- POJ 1704 Georgia and Bob【博弈】
题目链接: http://poj.org/problem?id=1704 题意: 给定棋子及其在格子上的坐标,两个人轮流选择一个棋子向左移动,每次至少移动一格,但是不可以碰到其他棋子.无路可走的时候视 ...
- [Bzoj1015][JSOI2008]星球大战starwar(并查集)(离线处理)
1015: [JSOI2008]星球大战starwar Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 6849 Solved: 3204[Submit ...
- 使用微软的 ilasm 和 ildasm 对. net程序进行编译和反编译
为了保证示例的完整性,请先准备好一个 c#写的 exe 程序,或者可以使用我提供的 exe 程序也可以(很简单,为了测试这里仅生成了一个带按钮的 winform,单击按钮提示弹窗) Test WinF ...
- Simics 破解 转
http://www.eetop.cn/blog/html/28/1066428-type-bbs-view-myfav.html http://blog.sina.com.cn/s/blog_538 ...
- webpack-Modules(模块)
模块(Modules) 在模块化编程中,开发者将程序分解成离散功能块(discrete chunks of functionality),并称之为模块. 每个模块具有比完整程序更小的接触面,使得校验. ...
- ZOJ 3228 Searching the String (AC自己主动机)
题目链接:Searching the String 解析:给一个长串.给n个不同种类的短串.问分别在能重叠下或者不能重叠下短串在长串中出现的次数. 能重叠的已经是最简单的AC自己主动机模板题了. 不能 ...
- [CSAPP]Bufbomb实验报告
Bufbomb实验报告 实验分析: level 0-3从test開始制运行,通过函数getbuf向外界读取一串内容(buf). Level 4 是通过參数-n,程序运行testn函数,调用getbuf ...
- 基于github for windows&github的团队协作基本操作
首先,我们要在github上团队协作.先要建立一个team.这个自行百度,在github上操作就是. 点击打开链接 这是我的有道文章(假设看不到图片的话) 今天主要讲的是怎么操作github for ...