Battlestation Operational

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

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=1nj=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 104

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
分析:莫比乌斯反演,d(n)=Σ(d|n) f(d) ;
   d(n)=Σi = (1~n)Σj = (1~i) i/j , f(n) = Σi = (1~n)Σj = (1~i) [gcd(i,j)==1] i/j; 
   要求 f(n), f(n) = d(n) - Σ(d|n) f(d) ( d != n);
代码:
#include<cstdio>
#define mod 1000000007
#define rep(i,m,n) for(i=m;i<=(int)n;i++)
const int maxn=1e6+;
int n,m,k,t;
long long p[maxn];
void init()
{
int i,j;
rep(i,,maxn-)
{
p[i]++;
p[i+]--;
for(int j=i,cnt=;j+<=maxn-;j+=i,cnt++)
{
p[j+]+=cnt;
if(j+i+<=maxn-)p[j+i+]-=cnt;
}
}
rep(i,,maxn-)p[i]=(p[i]%mod+p[i-]+mod)%mod;
rep(i,,maxn-)
{
for(j=i*;j<=maxn-;j+=i)
{
p[j]=(p[j]-p[i]+mod)%mod;
}
}
rep(i,,maxn-)(p[i]+=p[i-])%=mod;
}
int main()
{
int i,j;
init();
while(~scanf("%d",&n))printf("%lld\n",p[n]);
return ;
}

Battlestation Operational的更多相关文章

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

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

  2. hdu6134 Battlestation Operational 莫比乌斯第一种形式

    /** 题目:hdu6134 Battlestation Operational 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6134 题意:f(n) = ...

  3. 【2017多校训练08 1002】【HDOJ 6134】Battlestation Operational

    典型的数列反演题. 运用莫比乌斯反演的一个结论 $[n = 1] = \sum_{d | n} \mu(d)$,将表达式做如下转化: $$ ans = \sum_{i=1}^n \sum_{j=1}^ ...

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

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

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

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

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

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

  7. 【数论】【莫比乌斯反演】【线性筛】hdu6134 Battlestation Operational

    看这个题解吧:http://blog.csdn.net/wubaizhe/article/details/77338332 代码里顺便把几个常用的线性筛附上了. Key:1.gcd(i,j)==1利用 ...

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

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

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

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

随机推荐

  1. bzoj 1935 Tree 园丁的烦恼

    题目大意: 一些点,每次查询一个矩形内有多少个点 思路: 因为空间太大 所以不能用什么二维树状数组 需要把这些点和所有查询的矩阵的左下和右上离线下来 先离散化 然后每个子矩阵像二维前缀和那样查询 按照 ...

  2. 2-sat总结

    算法 构造一个有向图G,每个变量xi拆成两个点2i和2i+1 分别表示xi为假,xi为真 那么对于“xi为真或xj为假”这样的条件 我们就需要连接两条边 2*i —>2*j(表示如果i为假,那么 ...

  3. 42.extjs Combobox动态加载数据问题,mode:local 还是remote

    问题: Java代码   var fabircTypeDs = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url: 'province. ...

  4. Android.mk添加第三方jar包(转载)

    转自:www.cnblogs.com/hopetribe/archive/2012/04/23/2467060.html LOCAL_PATH:= $(call my-dir)include $(CL ...

  5. Akka源码分析-Persistence-AtLeastOnceDelivery

    使用过akka的应该都知道,默认情况下,消息是按照最多一次发送的,也就是tell函数会尽量把消息发送出去,如果发送失败,不会重发.但有些业务场景,消息的发送需要满足最少一次,也就是至少要成功发送一次. ...

  6. Oracle group by分组拼接字符串

    select wm_concat(id),depon  from test_1  group by depon

  7. Linux命令(004) -- watch

    对Linux系统的操作过程中,经常会遇到重复执行同一命令,以观察其结果变化的情况.惯用的方法是:上下键加回车,或是Ctr+p然后回车.今天我们来了解一下watch命令,它可以帮助我们周期性的执行一个命 ...

  8. dynamic_cast 与 typeid

    C++中的类型转换分为两种: 隐式类型转换: 显式类型转换. 隐式类型转换一般都是不经意间就发生了,比如int + float 时,int就被隐式的转换为float类型了. 显示类型转换包括四种方式: ...

  9. 【转】Java 集合系列12之 TreeMap详细介绍(源码解析)和使用示例

    概要 这一章,我们对TreeMap进行学习.我们先对TreeMap有个整体认识,然后再学习它的源码,最后再通过实例来学会使用TreeMap.内容包括:第1部分 TreeMap介绍第2部分 TreeMa ...

  10. Android 将图片网址url转化为bitmap

    public Bitmap returnBitMap(final String url){ new Thread(new Runnable() { @Override public void run( ...