CF757E. Bash Plays with Functions

给$q$个询问,$f_r(n)\% (1e9+7)$

显然是狄利克雷卷积。积性函数的卷积也是积性函数。

可以发现$f_0(p_1^k)=f_0(p_2^k)=2$与底数无关。

$f_{r+1}(p^k)=f_{r}(p^k)+..f_{r}(p^0)$ 预处理下即可。分解$n$质因数即可。

复杂度$O((n+r+q)\log n)$

代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mk make_pair
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
int addmod(int x, int y)
{
if (y < 0)
y += mod;
if (x + y >= mod)
x -= mod;
return x + y;
}
int v[N];
int dp[N][22];
int main()
{
for (int i = 0; i < 22; i++)
dp[0][i] = 2;
dp[0][0] = 1;
for (int i = 1; i < N; i++)
{
dp[i][0] = dp[i - 1][0];
for (int j = 1; j < 22; j++)
dp[i][j] = addmod(dp[i][j - 1], dp[i - 1][j]);
}

v[1] = 1;
for (int i = 2; i < N; i++)
if (!v[i])
for (int j = i; j < N; j += i)
v[j] = i;
int q;
scanf("%d", &q);
while (q--)
{
//cout << 233 << endl;
int r, n;
int ans = 1;
scanf("%d%d", &r, &n);
while (n != 1)
{
int num = 0, p = v[n];

while (n % p == 0)
n /= p, num++;
ans = 1ll * ans * dp[r][num] % mod;
}
printf("%d\n", ans);
}
}