2017多校第8场 HDU 6134 Battlestation Operational 莫比乌斯反演
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6134
题意:

解法:

那么g(n)怎么求,我们尝试打表发现g(n)是有规律的,g(n)=g(n-1)+d(n-1)+1,其中d(i)表示i的因子个数,这个我们是可以通过线性筛O(n)处理出来的,之后再O(n)维护g(i)的前缀和,就可以在单组sqrt(n)的复杂度下得到答案了。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6+10;
const LL mod = 1e9+7;
bool check[maxn];
LL mu[maxn],d[maxn],sum[maxn],cnt[maxn];
int prime[maxn];
void Mobius()
{
memset(check,false,sizeof(check));
d[1]=mu[1]=1LL;
int tot=0;
for(int i=2; i<maxn; i++){
if(!check[i]){
prime[tot++]=i;
d[i]=2;
cnt[i]=1;
mu[i]=-1;
}
for(int j=0; j<tot; j++){
if((LL)i*prime[j]>maxn) break;
check[i*prime[j]]=true;
if(i%prime[j]==0){
d[i*prime[j]] = d[i]/(cnt[i]+1)*(cnt[i]+2);
cnt[i*prime[j]] = cnt[i] + 1;
mu[i*prime[j]]=0;
break;
}
else{
d[i*prime[j]]=d[i]<<1;
cnt[i*prime[j]]=1;
mu[i*prime[j]]=-mu[i];
}
}
}
sum[1]=1;
for(int i=2; i<maxn; i++){
sum[i]=(sum[i-1]+d[i-1]+1)%mod;
}
for(int i=1; i<maxn; i++){
sum[i]=(sum[i]+sum[i-1])%mod;
mu[i]=(mu[i]+mu[i-1])%mod;
}
}
int main()
{
Mobius();
int n;
while(~scanf("%d",&n))
{
LL ans = 0;
int last;
for(int i=1; i<=n; i=last+1){
last=n/(n/i);
ans=(ans+(mu[last]-mu[i-1])%mod*sum[n/i]%mod)%mod;
}
ans = (ans+mod)%mod;
printf("%lld\n", ans);
}
return 0;
}
2017多校第8场 HDU 6134 Battlestation Operational 莫比乌斯反演的更多相关文章
- hdu 6134 Battlestation Operational 莫比乌斯反演
Battlestation Operational Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- hdu 6134 Battlestation Operational (莫比乌斯反演+埃式筛)
Problem Description > The Death Star, known officially as the DS-1 Orbital Battle Station, also ...
- hdu 6134: Battlestation Operational (2017 多校第八场 1002)【莫比乌斯】
题目链接 比赛时没抓住重点,对那个受限制的“分数求和”太过关心了..其实如果先利用莫比乌斯函数的一个性质把后面那个[gcd(i,j)=1]去掉,那么问题就可以简化很多.公式如下 这和之前做过的一道题很 ...
- 2017多校第9场 HDU 6170 Two strings DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6170 题意:给了2个字符串,其中第2个字符串包含.和*两种特别字符,问第二个字符串能否和第一个匹配. ...
- 2017多校第9场 HDU 6161 Big binary tree 思维,类似字典树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6161 题意: 题目是给一棵完全二叉树,从上到下从左到右给每个节点标号,每个点有权值,初始权值为其标号, ...
- 2017多校第9场 HDU 6169 Senior PanⅡ 数论,DP,爆搜
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6169 题意:给了区间L,R,求[L,R]区间所有满足其最小质数因子为k的数的和. 解法: 我看了这篇b ...
- 2017多校第10场 HDU 6181 Two Paths 次短路
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6181 题意:给一个图,求出次短路. 解法:我之前的模板不能解决这种图,就是最短路和次短路相等的情况,证 ...
- 2017多校第10场 HDU 6180 Schedule 贪心,multiset
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6180 题意:给了一些任务的开始时间和终止时间,现在让我们安排k台及机器,让这些任务在k太机器上最小,并 ...
- 2017多校第10场 HDU 6178 Monkeys 贪心,或者DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6178 题意:给出一棵有n个节点的树,现在需要你把k只猴子放在节点上,每个节点最多放一只猴子,且要求每只 ...
随机推荐
- FTP-Server
1.目录: 2. ftp_client.py import socket,os,json client=socket.socket() client.connect(('localhost',9999 ...
- Andorid API Package --->android.animation
包名: android.animation Added in API level 11 URL:http://developer.andr ...
- hadoop 使用Avro求最大值
在上例中:hadoop MapReduce辅助排序解析,为了求每年的最大数据使用了mapreduce辅助排序的方法. 本例中介绍利用Avro这个序列化框架的mapreduce功能来实现求取最大值.Av ...
- BZOJ1503:[NOI2004]郁闷的出纳员——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1503 (题面复制的洛谷的,因为洛谷好看) 题目描述 OIER公司是一家大型专业化软件公司,有着数以万 ...
- 国庆 Day1
This is a 玄学 exam A.年轮蛋糕 最小的最大,二分首选 断环为链,check(x),x为答案,然后将每个大于x的子区间记录下来 如果有大于3个的话,那么x就可以是答案 那么·,在优化下 ...
- Codeforces Round #331 (Div. 2) A
A. Wilbur and Swimming Pool time limit per test 1 second memory limit per test 256 megabytes input s ...
- [freemarker篇]05.关于集合的遍历
人啊,有的时候就是没有办法坚持一些事情,总是因为各种理由在推脱,逐渐就变成了拖延症!例如胖先生的减肥计划,其实本来就没有计划,属于散漫形式的!一直减肥,一直在肥!总是说没有时间,没有时间!其实有时候就 ...
- echarts 使用demo
<!DOCTYPE html> <head> <meta charset="utf-8"> <title>ECharts</t ...
- 【算法日记】2.算法中的大O符号
大O符号是一种算法复杂度的相对表示方式. 1.大O表示算法的操作数,表示出算法运行的快慢 2.大O表示法指出了最糟糕情况下的运行时间,例如 简单查找的运行时间O(n),意味着在最糟糕的情况下,必须运行 ...
- iOS tag的使用
一.添加标记 (标记不能为0) UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(,,,)]; backBtn.backgr ...