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. 2017 ACM-ICPC乌鲁木齐网络赛 B. Out-out-control cars(计算几何 直线相交)

    题目描述 Two out-of-control cars crashed within about a half-hour Wednesday afternoon on Deer Park Avenu ...

  2. 【HDOJ6611】K Subsequence(费用流)

    题意:给定一个长为n的正整数序列,要求从中取出至多k个不下降序列,使得它们的和最大,求这个和 n<=2e3,k<=10,a[i]<=1e5 思路:极其考验模板,反正我的spfa和zk ...

  3. NOIP普及组:买铅笔

    参加考试的时候,第一题我足足花了四十多分钟(因为那奇葩的键盘,幸好我向老师报告更换了键盘),还是只得了五十分... 题目描述: P老师需要去商店买n支铅笔作为小朋友们参加NOIP的礼物.她发现商店一共 ...

  4. [CSP-S模拟测试]:God Knows(线段树维护单调栈)

    题目描述 小$w$来到天堂的门口,对着天堂的大门发呆.大门上有一个二分图,左边第$i$个点连到右边第$p_i$个点.(保证$p_i$是一个排列).小$w$每次可以找左边某个对应连线尚未被移除的点$i$ ...

  5. python中匿名函数lamada函数的使用说明

    匿名函数lambda是指一类无需定义标识符(函数名 )的一类函数式或子程序.lambda函数可以 接受多个任意参数,并且返回单个表达式的值. 它的意义在于即插即用类型,不必定义名字,方便.它需要的返回 ...

  6. Mac上VMWare Fusion配置多台cent os

    一.创建虚拟机(准备工作) 1.使用VMWare Fusion 创建第一台虚拟机 2.选择操作系统(本次使用的是使用cent os 6.5 64bit 系统) 3.选择磁盘大小(楼主mac上的磁盘大小 ...

  7. 用threading 解决 gunicorn worker timeout

    产生worker timeout 的背景 while 1: ..... time.sleep(1) gunicorn运行起来,只等待了30s,就卡住了,没报任何异常或err,查了gunicorn 官方 ...

  8. CreateProcessEx创建进程

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

  9. 简单DP入门(二) 最长上升子序列及其优化

    最长上升子序列解决问题: 有N个数,求出它最长的上升子序列并输出长度. 在题里不会讲的这么直白,这个算法往往会与其他的算法混在一起使用. 在这篇文章中不会出现其他的例题,为了让大家更好的理解,我只会对 ...

  10. java中封装的使用方法(工具myeclipse)

    封装可以实现属性私有化,将类的属性修饰符由public改为private,如此做者,其他类就无法访问该类中被private修饰的对象,一般我们会使用setter/getter()方法实现对这些对象的访 ...