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. mybatis模糊查询(转载)

    原文地址:http://blog.csdn.net/luqin1988/article/details/7865643 模糊查询: 1. sql中字符串拼接 SELECT * FROM tableNa ...

  2. Mac 上使用svn 记录

    .启动svn服务器 svnadmin create /Users/liuwei/Desktop/svn/UI 如果本地有 UI这个目录了就不用再运行 使用这句就可以了 svnserve -d -r / ...

  3. sqlserver 中的时间算法

    DECLARE @Date DATETIME SET @Date=GETDATE() --前一天,给定日期的前一天 ,@Date) AS '前一天' --后一天,给定日期的后一天 ,@Date) AS ...

  4. The Rotation Game

    题目链接 题意:有八种操作棋盘进行移动,使得中间8个数字一样,问·最短移动步数及如何移动. 思路:dfs,因为当中间八个数字中有m个数字不同时,至少需要m次操作,将这个m作为估值.

  5. django-admin.py和manage.py的用法

    [简介] django-admin.py是Django的一个用于管理任务的命令行工具.本文将描述它的大概用法. 另外,在每一个Django project中都会有一个manage.py.manage. ...

  6. Oracle 11g 体系结构 --SGA PGA 前后台进程

    Oracle服务器主要由实例.数据库.程序全局区.前台进程 实例:用来提供管理数据库的功能 数据库:由Oracle数据库文件组成,用来存储系统数据 ;一般有:数据文件.控制文件.重做日志文件 而实例可 ...

  7. flask实现异步任务

    最近在开发同步mysql数据到redis的接口,因为数据同步涉及各种增删查改,如果用同步实现,可能回造成连接超时.堵塞,所以,使用python实现异步任务. 代码实现from flask import ...

  8. 禁止修改input内容

    有什么问题请到<a href='/bbs/index.asp?boardid=2'>论坛</a>中发表<br> <!--# 特效来源:http://www.o ...

  9. HBase–RegionServer宕机恢复原理

    Region Server宕机总述 HBase一个很大的特色是扩展性极其友好,可以通过简单地加机器实现集群规模的线性扩展,而且机器的配置并不需要太好,通过大量廉价机器代替价格昂贵的高性能机器.但也正因 ...

  10. spring cloud学习--eureka 01

    本博客为学习使用,学习教程翟永超 spring cloud 微服务实战 搭建eureka server注册中心 spring initialize构建spring boot项目 构建网址:https: ...