膜旺神,旺神太强了,旺神是我男神。
Battlestation Operational
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 296 Accepted Submission(s): 162
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/53a93ecb97414613240a2a1fb200734d.jpeg)
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
附:
此时目标求g(n)
最后:
//china no.1
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <stack>
#include <cstring>
#include <queue>
#include <list>
#include <stdio.h>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <functional>
#include <stdlib.h>
#include <time.h>
#include <bitset>
using namespace std;
#define pi acos(-1)
#define PI acos(-1)
#define endl '\n'
#define srand() srand(time(0));
#define me(x,y) memset(x,y,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define close() ios::sync_with_stdio(0); cin.tie(0);
#define FOR(x,n,i) for(int i=x;i<=n;i++)
#define FOr(x,n,i) for(int i=x;i<n;i++)
#define W while
#define sgn(x) ((x) < 0 ? -1 : (x) > 0)
#define bug printf("***********\n");
#define db double
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL LINF=0x3f3f3f3f3f3f3f3fLL;
const int dx[]={-1,0,1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,-1,1,-1,1};
const int maxn=1e5+10;
const int maxx=1e6+100;
const double EPS=1e-8;
const double eps=1e-8;
const int mod=1e9+7;
template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}
template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}
template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}
template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}
template <class T>
inline bool scan_d(T &ret){char c;int sgn;if (c = getchar(), c == EOF){return 0;}
while (c != '-' && (c < '0' || c > '9')){c = getchar();}sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');
while (c = getchar(), c >= '0' && c <= '9'){ret = ret * 10 + (c - '0');}ret *= sgn;return 1;}
inline bool scan_lf(double &num){char in;double Dec=0.1;bool IsN=false,IsD=false;in=getchar();if(in==EOF) return false;
while(in!='-'&&in!='.'&&(in<'0'||in>'9'))in=getchar();if(in=='-'){IsN=true;num=0;}else if(in=='.'){IsD=true;num=0;}
else num=in-'0';if(!IsD){while(in=getchar(),in>='0'&&in<='9'){num*=10;num+=in-'0';}}
if(in!='.'){if(IsN) num=-num;return true;}else{while(in=getchar(),in>='0'&&in<='9'){num+=Dec*(in-'0');Dec*=0.1;}}
if(IsN) num=-num;return true;}
void Out(LL a){if(a < 0) { putchar('-'); a = -a; }if(a >= 10) Out(a / 10);putchar(a % 10 + '0');}
void print(LL a){ Out(a),puts("");}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
//cerr << "run time is " << clock() << endl;
int tot,p[maxx],miu[maxx],v[maxx];
LL g[maxx],f[maxx],c[maxx];
void Mobius(int n)
{
int i,j;
for(miu[1]=1,i=2;i<=n;i++)
{
if(!v[i]) p[tot++]=i,miu[i]=-1;
for(j=0;j<tot&&i*p[j]<=n;j++)
{
v[i*p[j]]=1;
if(i%p[j]) miu[i*p[j]]=-miu[i];
else break;
}
}
}
void init()
{
int h=0;
for(int i=1;i<=maxx;i++)
{
for(int j=i;j<=maxx;j+=i)
{
c[j]++;//因子数
}
g[i]+=g[i-1]+h+i;
h+=c[i];
}
Mobius(maxx);
for(int i=1;i<=maxx;i++)
{
f[i]+=f[i-1];
if(miu[i])
{
for(int k=1,j=i;j<=maxx;j+=i,k++)
{
f[j]+=miu[i]*(g[k]-g[k-1]);
f[j]=(f[j]+mod)%mod;
}
}
}
}
int n;
int main()
{
init();
W(scan_d(n))
{
cout<<(f[n]+mod)%mod<<endl;
}
}
另:
莫比乌斯反演定理形式一:
F(n)=∑d|nf(d)=>f(n)=∑d|nμ(d)F(nd)
证明:
恒等变形得:
f(n)=∑d|nμ(d)F(nd)=∑d|nμ(d)∑k|ndf(k)=∑k|nf(k)∑d|nkμ(d)
因为之前证明的这个定理:
∑d|nμ(d)={10n==1n>1
所以当且仅当
nk=1
,即n=k时,
∑d|nkμ(d)=1
,其余时候等于0。
故
∑k|nf(k)∑d|nkμ(d)=f(n)
莫比乌斯反演定理形式二:
F(n)=∑n|df(d)=>f(n)=∑n|dμ(dn)F(d)
证明:
令 k=dn ,那么,就得到
f(n)=∑k=1+∞μ(k)F(nk)=∑k=1+∞μ(k)∑nk|tf(t)=∑n|tf(t)∑k|tnμ(k)
所以当且仅当 tn=1 ,即t=n时, ∑k|tnμ(k)=1 ,其余时候等于0。
故得到
∑n|tf(t)∑k|tnμ(k)=f(n)
证明完毕。
观察开头给出的表格,经过简单的代数变换,易发现μ函数的一些取值,即
μ(1) = 1
μ(2) = -1
μ(3) = -1
μ(4) = 0
μ(5) = -1
μ(6) = 1
定义莫比乌斯函数μ(d):
(1) d = 1时,μ(d) = 1
(2) d = p1 × p2 × … × pk ,(其中p1,p2..pk是互不相同的质数) 则μ(d) = (-1)^k (-1的k次幂)
(3) 其余情况 μ(d) = 0