HDU 6134 Battlestation Operational(莫比乌斯反演+线性筛)

Battlestation Operational

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

Source

2017 Multi-University Training Contest - Team 8 


HDU 6134 Battlestation Operational(莫比乌斯反演+线性筛)_第1张图片

HDU 6134 Battlestation Operational(莫比乌斯反演+线性筛)_第2张图片


计算步骤:1、素筛
       2、线性筛,计算1-N所有数的因子个数d[i],计算莫比乌斯函数m[i]
           3、计算g[n],g[n]=g[n-1]+d[n-1]+1;
       4、计算g[n]的前缀和res[n],m[n]的前缀和
g
     注意:计算f[n]时要进行优化(对于相同的n/d一起加),否则会t

#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
using namespace std;
const int N=1000005;
const int mod=1e9+7;
bool isprime[N];
int prime[N];
int c;
int d[N];
int m[N];
ll g[N];
ll res[N];
void getprime()
{
    c=0;
    memset(isprime,1,sizeof(isprime));
    memset(m,0,sizeof(m));
    isprime[0]=0;
    isprime[1]=0;
    for(int i=2,j=0;i




你可能感兴趣的:(ACM)