Battlestation Operational
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 734 Accepted Submission(s): 406
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.
>
> — 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.
![](https://i-blog.csdnimg.cn/blog_migrate/bda325b8e7d39bd3d65e7212aae74b60.png)
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 104 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
Source
Recommend
#include<iostream>
#include<algorithm>
#include<string>
#include<map>//int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0};
#include<set>//int gcd(int a,int b){return b?gcd(b,a%b):a;}
#include<vector>
#include<cmath>
#include<stack>
#include<string.h>
#include<stdlib.h>
#include<cstdio>
#define maxn 1000005
#define ll long long
#define INF 10000000
using namespace std;
const int MOD=1e9+7;
int n,d[maxn],G[maxn],F[maxn];//d数组表示数字i因子数的个数,G数组表示每一行的全部贡献值,F数组表示每一行的实际贡献值
//打表得到的规律为:G[i]=G[i-1]+d[i]+1;
//容斥定理是解决这一问题的基础,枚举i的倍数(从2*i开始)
void _table(int N)
{
for(int i=1;i<=N;i++)
for(int j=i;j<=N;j+=i)
d[j]++;
G[1]=1;
for(int i=2;i<=N;i++)
G[i]=(G[i-1]+d[i-1]+1)%MOD;
for(int i=1;i<=N;i++)
for(int j=i*2;j<=N;j+=i)
G[j]=(G[j]-G[i]+MOD)%MOD;
F[1]=G[1];
for(int i=2;i<=N;i++)
F[i]=(G[i]+F[i-1])%MOD;
}
int main( )
{
ios::sync_with_stdio(false);
_table(maxn);
while(cin>>n) cout<<F[n]<<endl;
return 0;
}