hdu 6134 Battlestation Operational (莫比乌斯反演+埃式筛)
>
> — Wookieepedia
In the story of the Rogue One, the rebels risked their lives stolen the construction plan of the Death Star before it can cause catastrophic damage to the rebel base. According to the documents, the main weapon of the Death Star, the Superlaser, emits asymmetric energy in the battlefield that cause photons to annihilate and burns everything in a single shot.
You are assigned the task to estimate the damage of one shot of the Superlaser.
Assuming that the battlefield is an n×n grid. The energy field ignited by the Superlaser is asymmetric over the grid. For the cell at i-th row and j-th column, ⌈i/j⌉units of damage will be caused. Furthermore, due to the quantum effects, the energies in a cell cancel out if gcd(i,j)≠1 or i<j.
The figure below illustrates the damage caused to each cell for n=100. A cell in black indicates that this cell will not be damaged due to the quantum effects. Otherwise, different colors denote different units of damages.
Your should calculate the total damage to the battlefield. Formally, you should compute
where [(i,j)=1] evaluates to be 1 if gcd(i,j)=1, otherwise 0.

//这句话没用.... 套路的看第二个sigma的上界可以直接写成n,于是就变成了
根据Q神的思路我们令
那么
为什么呢?
我们在求g(n)的时候不要求gcd(i,j)==1,那么我们枚举gcd(i,j)=d,那么对于d,它肯定是i的因子即 d|i
对于每个d,j有可能有 种答案 即从 d,2*d,3*d... (i/d)*d 这
个数中选择与i互质的统计起来
而 跟
一定是互质的.而且
那么上面的对于每一个d统计的结果就是
那么枚举d后即
可以用前缀和求出来.
而且
可以用二重nlogn的for循环求出,有点类似于埃式筛的思想
代码如下:
#include <bits/stdc++.h> using namespace std;
const int maxn = 1e6+;
const int mod = 1e9+;
int g[maxn];
int n;
void init()
{
for (int i=;i<=maxn-;++i){
g[i]++;
g[i+]--;
for (int j=i,cnt=;j+<=maxn-;j+=i,cnt++){
g[j+]+=cnt;
if (j++i<=maxn-) g[j++i]-=cnt;
}
}
for (int i=;i<=maxn-;++i)
g[i]=(g[i]%mod+g[i-]+mod)%mod; for (int i=;i<=maxn-;++i){
for (int j=i*;j<=maxn-;j+=i){
g[j]=(g[j]-g[i]+mod)%mod;
}
}
for (int i=;i<=maxn-;++i)
g[i]=(g[i]+g[i-])%mod;
}
int main()
{
init();
while (~scanf("%d",&n)){
printf("%d\n",g[n]%mod);
}
return ;
}
hdu 6134 Battlestation Operational (莫比乌斯反演+埃式筛)的更多相关文章
- hdu 6134 Battlestation Operational 莫比乌斯反演
Battlestation Operational Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- 2017多校第8场 HDU 6134 Battlestation Operational 莫比乌斯反演
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6134 题意: 解法: 那么g(n)怎么求,我们尝试打表发现g(n)是有规律的,g(n)=g(n-1)+ ...
- hdu.5212.Code(莫比乌斯反演 && 埃氏筛)
Code Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submi ...
- HDU 5608 function(莫比乌斯反演 + 杜教筛)题解
题意: 已知\(N^2-3N+2=\sum_{d|N}f(d)\),求\(\sum_{i=1}^nf(i) \mod 1e9+7\),\(n\leq1e9\) 思路: 杜教筛基础题? 很显然这里已经设 ...
- HDU 6134 Battlestation Operational(莫比乌斯反演)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6134 [题目大意] 求$\sum_{i=1}^{n}{\sum_{j=1}^{i}\lceil{\ ...
- 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)
题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...
- hdu 6134: Battlestation Operational (2017 多校第八场 1002)【莫比乌斯】
题目链接 比赛时没抓住重点,对那个受限制的“分数求和”太过关心了..其实如果先利用莫比乌斯函数的一个性质把后面那个[gcd(i,j)=1]去掉,那么问题就可以简化很多.公式如下 这和之前做过的一道题很 ...
- HDU 6134 Battlestation Operational | 2017 Multi-University Training Contest 8
破结论没听说过,上式推导到第三步的时候有了O(nlogn) 的做法(枚举倍数+1最后前缀和),并且这种做法可以直接应用到向上取整的计算中,详见forever97 但由于d(n)是积性函数,故可O(n) ...
- [复习]莫比乌斯反演,杜教筛,min_25筛
[复习]莫比乌斯反演,杜教筛,min_25筛 莫比乌斯反演 做题的时候的常用形式: \[\begin{aligned}g(n)&=\sum_{n|d}f(d)\\f(n)&=\sum_ ...
随机推荐
- Oracle数据库之触发器(一)
触发器trigger是数据库提供给程序员和数据分析员来保证数据完整性的一种方法,它是与表事件相关的特殊的存储过程,它的执行不是由程序调用,也不是手工启动,而是由事件来触发.比如当对一个表进行操作(in ...
- java配置和tomcat安装
原文: https://www.cnblogs.com/lwjboke/p/7089126.html 下载: jdk历史版本 下载地址: http://www.oracle.com/technetwo ...
- [CSP-S模拟测试]:attack(支配树+LCA+bitset)
题目传送门(内部题55) 输入格式 第一行,包含两个整数:$n,m,q$,表示敌军城市数.路数和情报数.接下来$m$行,每行包含两个整数:$u,v$,表示从$u$到$v$包含一条单向道路.接下来$q$ ...
- [CSP-S模拟测试]:壕游戏(费用流)
题目传送门(内部题18) 输入格式 第一行包括四个数$n,m,k,s$表示有$n$个剧情点,$m$个关卡,要玩$k$次游戏,$s$个完结点接下来一行包含$s$个数,代表$s$个完结点的编号.接下来$m ...
- wsl中加载git之后,发现文件是修改状态
查看git status,发现所有文件都被修改. git diff文件查看,发现是行尾的问题导致的. https://github.com/Microsoft/WSL/issues/184 在wsl里 ...
- 前端工具-让浏览器兼容ES6特性
babel:将ES6翻译为ES5 问题: 可以处理import和export么? 不能,还是用Rollup或者webpack打包一下吧 可以处理Promise么? 不能,还是使用babel-plugi ...
- 二分查找法:x 的平方根
实现 int sqrt(int x) 函数. 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去. public int mySqrt(int x) { long left=0; long r ...
- DomainObjectUtility
using System; using System.Collections; using System.Collections.Generic; using System.Collections.S ...
- Asp.Net Core 第02局:Program
总目录 前言 本文介绍Program,它包含程序的入口Main方法.从这里开始... 环境 1.Visual Studio 2017 2.Asp.Net Core 2.2 开局 第一手:Program ...
- MVC和WebApi 使用get和post 传递参数。 转载https://blog.csdn.net/qq373591361/article/details/51508806
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq373591361/article/details/51508806我们总结一下用js请求服务器的 ...