题目链接

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

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

题意:

当i于j不同时,ceil(i/j)的值可能取到一样或者不一样的值,不同的值代表着不同的颜色,求出在一个n*n的矩形的范围内,这样的值的和是多少。

分析:

已知:f(n) = sigma[1<=i<=n]sigma[1<=j<=i]ceil[i/j] (gcd(i,j)==1)

给定一个n,求f(n);

可以推出公式: n = sigma[d|n]phi[d] = sigma[d|n]phi[n/d];

phi[x]表示<=x的数与x互质的个数。

看一下这个公式的证明:

如果gcd(i,n)==d,那么可以得到:gcd(i/d,n/d)=1;

那么和n的最大公约数为d的个数为phi[n/d]; 所以n = sigma[d|n]phi[n/d] = sigma[d|n]phi[d];

根据n = sigma[d|n]phi[d];

那么有定义:

h(i)表示sigma[1<=j<=i]ceil[i/j] (gcd(i,j)==1) 这里的j都是和i互质时候计算的结果。

g(i)表示sigma[1<=j<=i]ceil[i/j](不用考虑i于j是否互质)

那么h(i) = sigma[d|i]mu[d]*g(i/d);

计算所有的g(d)(1<=d<=n)通过枚举j跳在d中跳的方式处理出来,然后前缀和(也可以直接计算出来。不需要再求前缀和,具体看代码)

计算出来所有的h(i)。f(i) = sigma[1<=j<=i]h(j);

说的可能不太好理解,具体的求解过程可以看一下这个

#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 1e6+10;
const int mod = 1e9 + 7;
LL f[N], g[N], h[N];
int prime[N], tot, not_prime[N];
int mu[N];
void mobius()///求出一个数字对应的莫比乌斯函数
{
mu[1] = 1;
tot = 0;
for(int i = 2; i < N; i++)
{
if(!not_prime[i])///如果当前的数字是质数,对应的莫比乌斯函数为-1
{
prime[++tot] = i;
mu[i] = -1;
}
for(int j = 1; prime[j]*i<N; j++)
{
not_prime[prime[j]*i] = 1;///prime[j]*i可以是单个的质数相乘的形式(不存在两个及以上相同的质数相乘)
if(i%prime[j]==0)///如果能将i用质数分解的话
{
mu[prime[j]*i] = 0;
break;
}
mu[prime[j]*i] = -mu[i];
}
}
} void init()
{
for(int i = 1; i < N; i++)
{
g[i]++;
for(int j = i+1; j < N; j+=i)
{
g[j]++;
}
}
for(int i = 1; i < N; i++) g[i] = (g[i]+g[i-1])%mod; for(int i = 1; i < N; i++)
{
for(int j = i; j < N; j+=i)
{
h[j] = (h[j]+mu[i]*g[j/i]%mod+mod)%mod;
}
}
for(int i = 1; i < N; i++)
{
f[i] = (f[i-1]+h[i])%mod;
}
}
int main()
{
int n;
mobius();
init();
while(scanf("%d",&n)==1)
{
printf("%lld\n",f[n]);
}
return 0;
}

{{IMG_20170820_172027.jpg(uploading...)}}

2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)的更多相关文章

  1. 2017ACM暑期多校联合训练 - Team 7 1002 HDU 6121 Build a tree (深搜+思维)

    题目链接 Problem Description HazelFan wants to build a rooted tree. The tree has n nodes labeled 0 to n− ...

  2. 2017ACM暑期多校联合训练 - Team 6 1002 HDU 6097 Mindis (数学)

    题目链接 Problem Description The center coordinate of the circle C is O, the coordinate of O is (0,0) , ...

  3. 2017ACM暑期多校联合训练 - Team 1 1002 HDU 6034 Balala Power! (字符串处理)

    题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He ...

  4. 2017ACM暑期多校联合训练 - Team 4 1004 HDU 6070 Dirt Ratio (线段树)

    题目链接 Problem Description In ACM/ICPC contest, the ''Dirt Ratio'' of a team is calculated in the foll ...

  5. 2017ACM暑期多校联合训练 - Team 9 1005 HDU 6165 FFF at Valentine (dfs)

    题目链接 Problem Description At Valentine's eve, Shylock and Lucar were enjoying their time as any other ...

  6. 2017ACM暑期多校联合训练 - Team 9 1010 HDU 6170 Two strings (dp)

    题目链接 Problem Description Giving two strings and you should judge if they are matched. The first stri ...

  7. 2017ACM暑期多校联合训练 - Team 8 1006 HDU 6138 Fleet of the Eternal Throne (字符串处理 AC自动机)

    题目链接 Problem Description The Eternal Fleet was built many centuries ago before the time of Valkorion ...

  8. 2017ACM暑期多校联合训练 - Team 8 1011 HDU 6143 Killer Names (容斥+排列组合,dp+整数快速幂)

    题目链接 Problem Description Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith ...

  9. 2017ACM暑期多校联合训练 - Team 8 1008 HDU 6140 Hybrid Crystals (模拟)

    题目链接 Problem Description Kyber crystals, also called the living crystal or simply the kyber, and kno ...

随机推荐

  1. 1014 我的C语言文法定义与C程序推导过程

    程序> -> <外部声明> | <程序> <外部声明> <外部声明> -> <函数定义> | <声明> < ...

  2. (十)Jmeter中的Debug Sampler介绍

    一.Debug Sampler介绍: 使用Jmeter开发脚本时,难免需要调试,这时可以使用Jmeter的Debug Sampler,它有三个选项:JMeter properties,JMeter v ...

  3. docker+mesos+marathon

    前言 (Core) [root@docker-slave ~]# uname -r 3.10.0-229.4.2.el7.x86_64 [root@docker-slave ~]# uname -m ...

  4. python OCR 图形识别

    1.pip install pyocr 2.pip install PIL 3.安装tesseract-ocr http://jaist.dl.sourceforge.net/project/tess ...

  5. jQuery多重事件绑定

    1. <a> a标签默认绑定了一个onclick事件,当自己再写一个onclick事件的时候,默认自己写的那个优先执行. 如下程序,先执行(123),然后再发生跳转. <!DOCTY ...

  6. [JLOI2011]飞行路线 最短路

    题面 题面 题解 这题不是很难,因为删代价的次数不多,因此我们只需要将最短路中的状态加一维表示已经删了几次,再转移即可 #include<bits/stdc++.h> using name ...

  7. 【BZOJ3714】Kuglarz(最小生成树)

    [BZOJ3714]Kuglarz(最小生成树) 题面 BZOJ Description 魔术师的桌子上有n个杯子排成一行,编号为1,2,-,n,其中某些杯子底下藏有一个小球,如果你准确地猜出是哪些杯 ...

  8. [ACM][2018南京预赛]Sum

    一.题面 样例输入: 2 5 8 样例输出: 8 14 二.思路 关键词:线性筛 在Zed的帮助下知道了这是一道线性筛的比较裸的题了.考试过程中肝这道题的时间最久,费了心思找到递推式后,发现根本不是在 ...

  9. python基础----函数的定义和调用、return语句、变量作用域、传参、函数嵌套、函数对象、闭包、递归函数

    1.函数的定义: 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 函数能提高应用的模块性,和代码的重复利用率.你已经知道Python提供了许多内建函数,比如print().但你也可 ...

  10. 《剑指offer》— JavaScript(9)变态跳台阶

    变态跳台阶 题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级--它也可以跳上n级.求该青蛙跳上一个n级的台阶总共有多少种跳法. 实现代码 function jumpFloor(number) { ...