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);
代码:
  1. #include<cstdio>
  2. #define mod 1000000007
  3. #define rep(i,m,n) for(i=m;i<=(int)n;i++)
  4. const int maxn=1e6+;
  5. int n,m,k,t;
  6. long long p[maxn];
  7. void init()
  8. {
  9. int i,j;
  10. rep(i,,maxn-)
  11. {
  12. p[i]++;
  13. p[i+]--;
  14. for(int j=i,cnt=;j+<=maxn-;j+=i,cnt++)
  15. {
  16. p[j+]+=cnt;
  17. if(j+i+<=maxn-)p[j+i+]-=cnt;
  18. }
  19. }
  20. rep(i,,maxn-)p[i]=(p[i]%mod+p[i-]+mod)%mod;
  21. rep(i,,maxn-)
  22. {
  23. for(j=i*;j<=maxn-;j+=i)
  24. {
  25. p[j]=(p[j]-p[i]+mod)%mod;
  26. }
  27. }
  28. rep(i,,maxn-)(p[i]+=p[i-])%=mod;
  29. }
  30. int main()
  31. {
  32. int i,j;
  33. init();
  34. while(~scanf("%d",&n))printf("%lld\n",p[n]);
  35. return ;
  36. }

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. PCB 规则引擎之编辑器(语法着色,错误提示,代码格式化)

    对于一个规则引擎中的脚本代码编辑器是非常关键的,因为UI控件直接使用对象是规则维护者,关系到用户体验,在选用脚本编辑器的功能时除了满足代码的编辑的基本编辑要求外,功能还需要包含;语法着色,错误提示,代 ...

  2. php的类型转换

    转自:http://www.tianzhigang.com/article.asp?id=280 PHP的数据类型转换属于强制转换,允许转换的PHP数据类型有: (int).(integer):转换成 ...

  3. php中strlen,mb_strlen,count之区别

    转自 http://www.cnblogs.com/mo-beifeng/archive/2011/08/09/2133039.html 这不是一个固定的数字.本文简要说明一下限制规则. strlen ...

  4. sql case when 用法

    sql语言中有没有类似C语言中的switch case的语句?? 没有,用case   when   来代替就行了.            例如,下面的语句显示中文年月         select  ...

  5. linux 查看内存和cpu

    Linux查看CPU和内存使用情况 在系统维护的过程中,随时可能有需要查看 CPU 使用率,并根据相应信息分析系统状况的需要.在 CentOS 中,可以通过 top 命令来查看 CPU 使用状况.运行 ...

  6. linux命令(006) -- w

    w命令用于显示已经登陆系统的用户列表,并显示用户正在执行的指令.执行这个命令可得知目前登入系统的用户有那些人,以及他们正在执行的程序.单独执行w命令会显示所有的用户,您也可指定用户名称,仅显示某位用户 ...

  7. [转]linux之patch命令

    转自:http://blog.chinaunix.net/uid-9525959-id-2001542.html patch [选项] [原始文件 [补丁文件]] [功能] 给文件1应用补丁文件变成另 ...

  8. WinForm窗体项目 之 MySchool管理系统终极版

    学习WinForm窗体程序也有一段时间了,今天就来尝试着来一个项目热热身~ 在我们通常使用的MySchool管理中,不外乎这几种功能:增.删.改.查.改密码 在过去的C#中确实是挺简单的,但是在学习了 ...

  9. 在Django中使用redis:包括安装、配置、启动。

    一.安装redis: 1.下载: wget http://download.redis.io/releases/redis-3.2.8.tar.gz 2.解压 tar -zxvf redis-.tar ...

  10. Android 控制硬加速 hardwareAccelerated

    从Android3.0 (API level11)开始,Android的2D显示管道被被设计得更加支持硬加速了.硬加速使用GPU承担了所有在View的canvas上执行的绘制操作. 启用硬加速最简单的 ...