莫比乌斯函数之和(51nod 1244)
输入包括两个数a, b,中间用空格分隔(2 <= a <= b <= 10^10)
输出S(a, b)。
3 10
-1
#include<cstdio>
#include<iostream>
#define N 2000010
#define mod 2333333
#define lon long long
#ifdef unix
#define LL "%lld"
#else
#define LL "%I64d"
#endif
using namespace std;
int pri[N],num,mul[N],mark[N],sum[N],head[mod+],cnt;
struct node{
lon to;int pre,val;
};node e[N];
void get_prime(){
mul[]=;
for(int i=;i<N;i++){
if(!mark[i]) pri[++num]=i,mul[i]=-;
for(int j=;j<=num&&i*pri[j]<N;j++){
mark[i*pri[j]]=;
mul[i*pri[j]]=-mul[i];
if(i%pri[j]==){mul[i*pri[j]]=;break;}
}
}
}
void add(int u,lon v,int val){
e[++cnt].to=v;
e[cnt].val=val;
e[cnt].pre=head[u];
head[u]=cnt;
}
int solve(lon x){
if(x<N) return sum[x];
int y=x%mod,r=;
for(int i=head[y];i;i=e[i].pre)
if(e[i].to==x) return e[i].val;
lon last;
for(lon i=;i<x;i=last+){
last=(x/(x/i));
r-=solve(x/i)*(last-i+);
}
add(y,x,r);
return r;
}
int main(){
lon a,b;scanf(LL LL,&a,&b);
get_prime();
for(int i=;i<N;i++) sum[i]=sum[i-]+mul[i];
printf("%d",solve(b)-solve(a-));
return ;
}
莫比乌斯函数之和(51nod 1244)的更多相关文章
- [51Nod 1244] - 莫比乌斯函数之和 & [51Nod 1239] - 欧拉函数之和 (杜教筛板题)
[51Nod 1244] - 莫比乌斯函数之和 求∑i=1Nμ(i)\sum_{i=1}^Nμ(i)∑i=1Nμ(i) 开推 ∑d∣nμ(d)=[n==1]\sum_{d|n}\mu(d)=[n== ...
- 51nod 1244 莫比乌斯函数之和
题目链接:51nod 1244 莫比乌斯函数之和 题解参考syh学长的博客:http://www.cnblogs.com/AOQNRMGYXLMV/p/4932537.html %%% 关于这一类求积 ...
- 51nod 1244 莫比乌斯函数之和 【杜教筛】
51nod 1244 莫比乌斯函数之和 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens)首先使用μ(n)(miu(n))作为莫比乌斯函数的记号.具体定义如下: 如果一个数包含 ...
- 51 NOD 1244 莫比乌斯函数之和(杜教筛)
1244 莫比乌斯函数之和 基准时间限制:3 秒 空间限制:131072 KB 分值: 320 难度:7级算法题 收藏 关注 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens) ...
- 51nod1244 莫比乌斯函数之和
推公式.f[n]=1-∑f[n/i](i=2...n).然后递归+记忆化搜索.yyl说这叫杜教筛?时间复杂度貌似是O(n 2/3)的? #include<cstdio> #include& ...
- 51nod 1244 莫比乌斯函数之和(杜教筛)
[题目链接] http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 [题目大意] 计算莫比乌斯函数的区段和 [题解] 利 ...
- 【51nod-1239&1244】欧拉函数之和&莫比乌斯函数之和 杜教筛
题目链接: 1239:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1239 1244:http://www.51nod. ...
- 【51Nod 1244】莫比乌斯函数之和
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 模板题... 杜教筛和基于质因子分解的筛法都写了一下模板. 杜教筛 ...
- 【51nod】1244 莫比乌斯函数之和
题解 求积性函数的前缀和?杜教筛! 这不给一发杜教筛入门必备之博客= = https://blog.csdn.net/skywalkert/article/details/50500009 好了,然后 ...
随机推荐
- C#数组删除元素
一.C#数组删除元素 在C#中,只能在动态数组ArrayList类中对数组执行删除元素的操作.因为动态数组是一个可以改变数组长度和元素个数的数据类型. 示例: using System;using S ...
- java中异常处理机制 throw抛出自定义业务逻辑异常 throws继续抛出 catch捕获后会自动继续抛向调用方法
package com.swift; public class Exception_TestC { public static void main(String[] args) { /* * 第5题: ...
- [LUOGU] P3952 时间复杂度
其实,也没那么难写 这种模拟题,仔细分析一下输入格式,分析可能的情况,把思路写在纸上,逐步求精,注意代码实现 主要思路就是算一个时间复杂度,和给出的复杂度比较,这就先设计一个函数把给出的复杂度由字符串 ...
- html5音频audio对象封装成vue组件的方式调用以及setTimeout如何在vue2生效 (vue2正在熟悉中,ajax还是用jQuery来写舒服些,里面含有一些php写法可略过) 此网页应用在PC不考虑手机端
// vue2 组件封装如下: <template> <div> <div><!--vue element 组件的引用 Switch 开关 不懂请自行百度(重 ...
- JQuery 在线编辑器和手册
JQuery 在线编辑器 JQuery 在线编辑器 JQuery 菜鸟教程 手册 JQuery 菜鸟教程 手册
- R-barplot()
barplot这个函数啊...坑...度娘的很多解决方案都不对,只好重新看回manual再做测试== 本文参考的是: https://stat.ethz.ch/R-manual/R-devel/lib ...
- How to setup multimedia on CentOS 7
You will need to also install the EPEL repository as nux-dextop depends on this for some of its pack ...
- CDH4 journalnode方式手工安装手册之二
一. Hadoop配置修改 修改core-site.xml文件 <configuration> <property> ...
- HBase0.94.2-cdh4.2.0需求评估测试报告1.0之五
根据以上图分析得出以下结论: 1. 在上面的hbase配置下,顺序和随机写记录(每条记录1K),每写入86-87M(大小可配)左右数据生成一个磁盘文件(store file). 2. 在上面的hbas ...
- Python使用asyncio+aiohttp异步爬取猫眼电影专业版
asyncio是从pytohn3.4开始添加到标准库中的一个强大的异步并发库,可以很好地解决python中高并发的问题,入门学习可以参考官方文档 并发访问能极大的提高爬虫的性能,但是requests访 ...