题目链接: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 莫比乌斯反演的更多相关文章

  1. hdu 6134 Battlestation Operational 莫比乌斯反演

    Battlestation Operational Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  2. hdu 6134 Battlestation Operational (莫比乌斯反演+埃式筛)

    Problem Description   > The Death Star, known officially as the DS-1 Orbital Battle Station, also ...

  3. hdu 6134: Battlestation Operational (2017 多校第八场 1002)【莫比乌斯】

    题目链接 比赛时没抓住重点,对那个受限制的“分数求和”太过关心了..其实如果先利用莫比乌斯函数的一个性质把后面那个[gcd(i,j)=1]去掉,那么问题就可以简化很多.公式如下 这和之前做过的一道题很 ...

  4. 2017多校第9场 HDU 6170 Two strings DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6170 题意:给了2个字符串,其中第2个字符串包含.和*两种特别字符,问第二个字符串能否和第一个匹配. ...

  5. 2017多校第9场 HDU 6161 Big binary tree 思维,类似字典树

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6161 题意: 题目是给一棵完全二叉树,从上到下从左到右给每个节点标号,每个点有权值,初始权值为其标号, ...

  6. 2017多校第9场 HDU 6169 Senior PanⅡ 数论,DP,爆搜

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6169 题意:给了区间L,R,求[L,R]区间所有满足其最小质数因子为k的数的和. 解法: 我看了这篇b ...

  7. 2017多校第10场 HDU 6181 Two Paths 次短路

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6181 题意:给一个图,求出次短路. 解法:我之前的模板不能解决这种图,就是最短路和次短路相等的情况,证 ...

  8. 2017多校第10场 HDU 6180 Schedule 贪心,multiset

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6180 题意:给了一些任务的开始时间和终止时间,现在让我们安排k台及机器,让这些任务在k太机器上最小,并 ...

  9. 2017多校第10场 HDU 6178 Monkeys 贪心,或者DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6178 题意:给出一棵有n个节点的树,现在需要你把k只猴子放在节点上,每个节点最多放一只猴子,且要求每只 ...

随机推荐

  1. 去除安卓手机select下拉框默认箭头

    -webkit-appearance: listbox;

  2. hdu 1068 Girls and Boys (二分匹配)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. Hadoop Yarn-入门篇

    参考并推荐博文:https://www.ibm.com/developerworks/cn/opensource/os-cn-hadoop-yarn/ 重构根本的思想是将 JobTracker 两个主 ...

  4. mysql 密码忘记

    新版本 再去掉 /etc/my.cnf

  5. (转)关于block使用的5点注意事项

    1.在使用block前需要对block指针做判空处理. 不判空直接使用,一旦指针为空直接产生崩溃. if (!self.isOnlyNet) { if (succBlock == NULL) { // ...

  6. 蓝桥杯 最短路 spfa

    问题描述 给定一个n个顶点,m条边的有向图(其中某些边权可能为负,但保证没有负环).请你计算从1号点到其他点的最短路(顶点从1到n编号). 输入格式 第一行两个整数n, m. 接下来的m行,每行有三个 ...

  7. Ruby环境搭建

    刚接触Ruby,发现Ruby真心强大,搞了那么久的Java了,已经被Java的繁琐的语法整的无语透顶了,尤其的Java异常,设计出来就是个失败呀!Ruby目前更新到了2.x了,社区也很活跃,开发效率和 ...

  8. mysql的concat用法

    问题提出:mybatis的mapper文件中的模糊查询: mysql CONCAT()函数用于将多个字符串连接成一个字符串,是最重要的mysql函数之一,下面就将为您详细介绍mysql CONCAT( ...

  9. SqlServer中循环和条件语句示例!

    -- ╔════════╗ -- =============================== ║ if语句使用示例 ║ -- ╚════════╝ declare @a int set @a=12 ...

  10. 转载《mysql 一》:mysql的select查询语句内在逻辑执行顺序

    原文:http://www.jellythink.com/archives/924 我的抱怨 我一个搞应用开发的,非要会数据库,这不是专门的数据库开发人员干的事么?话说,小公司也没有数 据库开发人员这 ...