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中日期转换
oracle中,日期转换函数有很多,常用命令如下: to_char()命令将时间戳转换为用户规定的日期格式,如: SELECT TO_CHAR(sysdate,'YYYY-MM-DD hh24:mi: ...
- CSD编码----数字信号处理--006
有符号数(Signed Digit Number , SD) SD编码 1.有三重值 {0,1,-1} 2.应用在不用进位的加法器或乘法器中能够降低复杂性 因为通常可以通过非零元素的数来估计乘法的工作 ...
- 【Java】定义Logger为什么要用static和final?
private static final Logger logger= LoggerFactory.getLogger(ShiroConfig.class); (1)出于资源利用的考虑,Logger的 ...
- NOIp 图论算法专题总结 (3):网络流 & 二分图 简明讲义
系列索引: NOIp 图论算法专题总结 (1) NOIp 图论算法专题总结 (2) NOIp 图论算法专题总结 (3) 网络流 概念 1 容量网络(capacity network)是一个有向图,图的 ...
- [CSP-S模拟测试]:联盟(搜索+树的直径)
题目描述 $G$国周边的$n$个小国家构成一个联盟以抵御$G$国入侵,为互相支援,他们建立了$n−1$条双向通路,使得任意两个国家可以经过通路相互到达.当一个国家受到攻击时,所有其它国家都会沿着最短路 ...
- static、final修饰的变量和方法能否被继承的问题
首先定义父类和子类 public class Parent { protected static String a = "static"; final String b = &qu ...
- /proc/interrupts /proc/stat 查看中断信息
/proc/interrupts列出当前所以系统注册的中断,记录中断号,中断发生次数,中断设备名称 如下图:从左至右:中断号 中断次数 中断设备名称 从上图可知中断号为19的arch_timer ...
- cortable 使用方法
星期一到星期六,早上六点到晚上六点.每隔两个小时 执行语句 0 6-18/2 * * 1-6 commond
- xshell的安装及连接linux的使用方法
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/lx_Frolf/article/deta ...
- 安装Elasticsearch5.4.0以及head,kibana插件
可以在网盘中下载也可以去官网下载 网盘: Elasticsearch 地址:http://pan.baidu.com/s/1hrI0AFU elasticsearch-head 地址:http:// ...