HDU 6134 Battlestation Operational(基本数论+莫比乌斯反演)——2017 Multi-University Training Contest - Team 8
2017-08-27 14:10
537 查看
传送门
Total Submission(s): 570 Accepted Submission(s): 317
[align=left]Problem Description[/align] > 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.
![](../../../data/images/C766-1002-1.jpg)
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.
[align=left]Input[/align] 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.
[align=left]Output[/align] For each test case, output one integer in one line denoting the total damage of the Superlaser, f(n) mod 109+7.
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
题目大意:
求如下式子的值:
f(n)=∑i=1n∑j=1i⌈ij⌉[(i,j)=1]
[(i,j)=1]表示:gcd(i,j)=1,[(i,j)=1]=1gcd(i,j)!=1,[(i,j)=1]=0
解题思路:
设有f(i)=∑j=1i⌈ij⌉[(i,j)=1],F(i)=∑j=1i⌈ij⌉然后我们发现:
F(i)=∑d|if(d)经过莫比乌斯反演之后:
f(i)=∑d|iμ(d)∗F(id)
现在问题的关键就是如何求 F(x)
打个表发现 F(1)=1,F(2)=3,F(3)=6,F(4)=9,..., 推出(猜出) F(x) 的递推公式: F(n)=F(n−1)+d(n−1)+1,其中d(n):n的因子个数
那么我们可以通过素因子分解得到 F(n),进一步求得 f(n),最后求 ans(n)=∑i=1nf(i)
复杂度分析: 预处理阶段是 O(nlog(n)),查询阶段 O(1)
代码:
Battlestation Operational
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 570 Accepted Submission(s): 317
[align=left]Problem Description[/align] > 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.
![](../../../data/images/C766-1002-1.jpg)
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.
[align=left]Input[/align] 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.
[align=left]Output[/align] For each test case, output one integer in one line denoting the total damage of the Superlaser, f(n) mod 109+7.
[align=left]Sample Input[/align]
1 2 3 10
[align=left]Sample Output[/align]
1 3 8 110
题目大意:
求如下式子的值:
f(n)=∑i=1n∑j=1i⌈ij⌉[(i,j)=1]
[(i,j)=1]表示:gcd(i,j)=1,[(i,j)=1]=1gcd(i,j)!=1,[(i,j)=1]=0
解题思路:
设有f(i)=∑j=1i⌈ij⌉[(i,j)=1],F(i)=∑j=1i⌈ij⌉然后我们发现:
F(i)=∑d|if(d)经过莫比乌斯反演之后:
f(i)=∑d|iμ(d)∗F(id)
现在问题的关键就是如何求 F(x)
打个表发现 F(1)=1,F(2)=3,F(3)=6,F(4)=9,..., 推出(猜出) F(x) 的递推公式: F(n)=F(n−1)+d(n−1)+1,其中d(n):n的因子个数
那么我们可以通过素因子分解得到 F(n),进一步求得 f(n),最后求 ans(n)=∑i=1nf(i)
复杂度分析: 预处理阶段是 O(nlog(n)),查询阶段 O(1)
代码:
#include <iostream> #include <string.h> #include <string> #include <algorithm> #include <stdio.h> #include <stdlib.h> #include <math.h> using namespace std; typedef long long LL; const int MAXN = 1e6+5; const double PI = acos(-1); const double eps = 1e-8; const LL MOD = 1e9+7; namespace IO { const int MX = 4e7; //1e7占用内存11000kb char buf[MX]; int c, sz; void begin() { c = 0; sz = fread(buf, 1, MX, stdin); } inline bool read(int &t) { while(c < sz && buf[c] != '-' && (buf[c] < '0' || buf[c] > '9')) c++; if(c >= sz) return false; bool flag = 0; if(buf[c] == '-') flag = 1, c++; for(t = 0; c < sz && '0' <= buf[c] && buf[c] <= '9'; c++) t = t * 10 + buf[c] - '0'; if(flag) t = -t; return true; } } int p[MAXN], mu[MAXN]; bool prime[MAXN]; int cnt = 0; void Mobius(){ memset(prime, false, sizeof(prime)); cnt = 0; mu[1] = 1; for(int i=2; i<MAXN; i++){ if(!prime[i]){ p[cnt++] = i; mu[i] = -1; } for(int j=0; j<cnt; j++){ if(1LL*i*p[j] > MAXN) break; int tp = i * p[j]; prime[tp] = true; if(i%p[j] == 0){ mu[tp]=0; break; } else mu[tp] = -mu[i]; } } } int fac[60], num[60]; int _cnt = 0; void Dec(int n){ _cnt = 0; memset(num, 0, sizeof(num)); for(int i=0; p[i]*p[i]<=n&&i<cnt; i++){ if(n%p[i]==0){ fac[_cnt] = p[i]; while(n%p[i]==0) n/=p[i], num[_cnt]++; _cnt++; } } if(n > 1) fac[_cnt] = n, num[_cnt++] = 1; } LL F[MAXN], ans[MAXN]; void Init(){ Mobius(); F[1] = 1; for(int i=2; i<MAXN; i++){ Dec(i-1); int tmp = 1; for(int i=0; i<_cnt; i++) tmp = tmp * (num[i] + 1); F[i] = tmp + 1; } for(int i=2; i<MAXN; i++) F[i] = (F[i]+F[i-1])%MOD; memset(ans, 0, sizeof(ans)); for(int i=1; i<MAXN; i++){ for(int j=i; j<MAXN; j+=i){ ans[j] = (ans[j]+mu[i]*F[j/i])%MOD; } } for(int i=2; i<MAXN; i++) ans[i] = ((ans[i] + ans[i-1])%MOD+MOD)%MOD; } int main(){ //freopen("C:/Users/yaonie/Desktop/in.txt", "r", stdin); //freopen("C:/Users/yaonie/Desktop/out.txt", "w", stdout); Init(); int n; while(~scanf("%d", &n)){ printf("%d\n",ans ); } return 0; }
相关文章推荐
- HDU 6134 Battlestation Operational | 2017 Multi-University Training Contest 8
- HDU 6128 Inverse of sum(数论)——2017 Multi-University Training Contest - Team 7
- hdu 6053 莫比乌斯反演函数的利用 2017 Multi-University Training Contest - Team 2
- 2017 Multi-University Training Contest - Team 1 1006&&HDU 6038 Function【DFS+数论】
- 【2017 Multi-University Training Contest - Team 7 && hdu 6121】Build a tree
- 2017 Multi-University Training Contest - Team 1:KazaQ's Socks(hdu 6043)
- HDU-6178 Monkeys - 2017 Multi-University Training Contest - Team 10(树形DP)
- hdu 6047 Maximum Sequence(2017 Multi-University Training Contest - Team 2)
- hdu 6045 Is Derek lying?(2017 Multi-University Training Contest - Team 2)
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- HDU 6053 TrickGCD(分块+容斥)——2017 Multi-University Training Contest - Team 2
- hdu 6058 Kanade's sum(链表)(2017 Multi-University Training Contest - Team 3 )
- hdu 6069 Counting Divisors(约数个数)(2017 Multi-University Training Contest - Team 4 )
- hdu 6070 Dirt Ratio(二分+线段树)(2017 Multi-University Training Contest - Team 4 )
- hdu 6071 Lazy Running(优先队列+dijkstra)(2017 Multi-University Training Contest - Team 4)
- hdu 6073 Matching In Multiplication(2017 Multi-University Training Contest - Team 4 )
- hdu 6034 Balala Power!(贪心)( 2017 Multi-University Training Contest - Team 1 )(无耻之sort)
- hdu 6047 Maximum Sequence(2017 Multi-University Training Contest - Team 2)
- hdu 6045 Is Derek lying?(2017 Multi-University Training Contest - Team 2)
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)