莫比乌斯函数之和(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++ Stack 与String
// ConsoleApplication1.cpp : 此文件包含 "main" 函数.程序执行将在此处开始并结束. // #include "pch.h" ...
- 【思维题 集合hash 树上差分】11.5撸树
要注重问题的转化和一些结论的推断 题目描述 要致富,先撸树. 一棵树的形状可以简化为一张 $N$ 个点 $M$ 条边的图,由于装备条件限制,你只有撸两次,也就是删去两条边,当这张图不联通时,就意味着树 ...
- nginx的url重写
1.1 简介 url重写由ngx_http_rewrite_module模块提供,默认会安装,但该模块功能的实现需要pcre.URL重写技术不仅要求掌握几个指令的语法.熟悉简单的正则表达式,还需要尽量 ...
- cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
参考 http://blog.csdn.net/mazicwong/article/details/54946952 1.到https://curl.haxx.se/ca/cacert.pem复制下 ...
- SEO 优化
1.什么是SEO优化: 简单的来说就是了解搜索引擎的排名规则,投机所好,让我们的网站在搜索引擎上得到靠前的排名,获取更多流量的一种方式. 2.SEO优化-衡量标准 关键词的排名--核心关键词的效果 收 ...
- 【windows】【md5】查看文件的md5值
certutil -hashfile filename MD5 certutil -hashfile filename SHA1 certutil -hashfile filename SHA256 ...
- NOIP 2017 小凯的疑惑
# NOIP 2017 小凯的疑惑 思路 a,b 互质 求最大不能表示出来的数k 则k与 a,b 互质 这里有一个结论:(网上有证明)不过我是打表找的规律 若 x,y(设x<y) 互质 则 : ...
- 妹子图爬取__RE__BS4
妹子图爬取 页面链接 感谢崔大佬: 原文链接 正则实现代码: import requests import re import os import random class mzitu(): def ...
- 使用jquery.layout.js构建页眉/页脚/左侧导航/中间展示内容的网页结构
背景: 快速将一个页面分成几个部分,在导航和页眉的位置放置公用的元素. 准备: jquery.layout.js 首先,向页面中引入如下js文件和css文件,代码: <link href=&qu ...
- 将系统从.Net Core2.0升级到.Net Core2.1
最近将手头的一个.Net Core2.0开发的小系统升级到最新的Core2.1.升级期间遇到了一些问题,现将问题以及解决方法整理汇总一下. 一是作为笔记,二也为跟各位分享一下.如过能帮到看到这帖子的人 ...