Problem Description
 
> The Death Star, known officially as the DS-1 Orbital Battle Station, also known as the Death Star I, the First Death Star, Project Stardust internally, and simply the Ultimate Weapon in early development stages, was a moon-sized, deep-space mobile battle station constructed by the Galactic Empire. Designed to fire a single planet-destroying superlaser powered by massive kyber crystals, it was the pet project of the Emperor, Darth Vader, and its eventual commander Grand Moff Wilhuff Tarkin to expound the military philosophy of the aptly named Tarkin Doctrine.
>
> — 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

f(n)=∑i=1n∑j=1i⌈ij⌉[(i,j)=1],

where [(i,j)=1] evaluates to be 1 if gcd(i,j)=1, otherwise 0.

 
Input
There are multiple test cases.Each line of the input, there is an integer n (1≤n≤106), as described in the problem. There are up to 10^4 test cases.
 Output
For each test case, output one integer in one line denoting the total damage of the Superlaser, f(n) mod 109+7.
 
Sample Input
1
2
3
10
 Sample Output
1
3
8
 
110
 
出题人是个星战狂魔前面不用看.
就是让你计算
 

//这句话没用....  套路的看第二个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 (莫比乌斯反演+埃式筛)的更多相关文章

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

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

  2. 2017多校第8场 HDU 6134 Battlestation Operational 莫比乌斯反演

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6134 题意: 解法: 那么g(n)怎么求,我们尝试打表发现g(n)是有规律的,g(n)=g(n-1)+ ...

  3. hdu.5212.Code(莫比乌斯反演 && 埃氏筛)

    Code Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submi ...

  4. HDU 5608 function(莫比乌斯反演 + 杜教筛)题解

    题意: 已知\(N^2-3N+2=\sum_{d|N}f(d)\),求\(\sum_{i=1}^nf(i) \mod 1e9+7\),\(n\leq1e9\) 思路: 杜教筛基础题? 很显然这里已经设 ...

  5. HDU 6134 Battlestation Operational(莫比乌斯反演)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6134 [题目大意] 求$\sum_{i=1}^{n}{\sum_{j=1}^{i}\lceil{\ ...

  6. 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)

    题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...

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

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

  8. HDU 6134 Battlestation Operational | 2017 Multi-University Training Contest 8

    破结论没听说过,上式推导到第三步的时候有了O(nlogn) 的做法(枚举倍数+1最后前缀和),并且这种做法可以直接应用到向上取整的计算中,详见forever97 但由于d(n)是积性函数,故可O(n) ...

  9. [复习]莫比乌斯反演,杜教筛,min_25筛

    [复习]莫比乌斯反演,杜教筛,min_25筛 莫比乌斯反演 做题的时候的常用形式: \[\begin{aligned}g(n)&=\sum_{n|d}f(d)\\f(n)&=\sum_ ...

随机推荐

  1. Debug模式自定义NSlog

    #ifdef DEBUG # define DLog(fmt, ...) NSLog((@"[文件名:%s]\n" "[函数名:%s]\n" "[行号 ...

  2. ldd3 编写scull尝试

    快速参考: #include <linux/types.h> dev_t dev_t is the type used to represent device numbers within ...

  3. 2019 牛客暑期多校 第二场 H Second Large Rectangle (单调栈)

    题目:https://ac.nowcoder.com/acm/contest/882/H 题意:一个大的01矩阵,然后现在要求第二大的全一矩阵是多少 思路:在这里我们首先学习一下另一个东西,怎么求直方 ...

  4. sublime常用基础插件合集

    插件介绍 Package Control 功能:安装包管理简介:sublime插件控制台,提供添加.删除.禁用.查找插件等功能使用方法:快捷键 Ctrl+Shift+P,输入 install 选中In ...

  5. webform将一个usercontrol作为模态框在page上弹出

    弹窗 public static void RegisterJQueryDialogScript(Page page, string dialogDivId, string title, int wi ...

  6. html常用代码

    <marquee width="70%" scrollamount="2">大家好</marquee>    // 大家好 字符从左到右 ...

  7. (66) c# async await

    1.使用 async await 2.返回值 static void Main(string[] args) { Program p = new Program(); Console.WriteLin ...

  8. iview+vue 表格中添加图片

    开门见山,话不多说,要在表格中添加图片,可以使用td: <table " width="100%"> <tr class="tr-style ...

  9. 距离矢量路由协议——RIP

    距离矢量路由协议RIP: 众所周知,RIP(Routing Information Protocol),即路由信息协议,是一种距离矢量路由协议,它与IGRP,OSPF等一样都是属于IGP(Interi ...

  10. CreateProcessEx创建进程

    NTSYSCALLAPI NTSTATUS NTAPI NtCreateProcess( OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess ...