标签:def 空间复杂度 哪些 get ret sqrt har long color
\(σ_0(i)\) 表示\(i\) 的约数个数
求\(S_k(n)=\sum_{i=1}^n\sigma_0(i^k)\mod 2^{64}\)
第一行一个T为数据组数
接下来每组数据一个n,一个k
每个询问输出一行
5
1 3
2 3
3 3
10 3
100 3
1
5
9
73
2302
\(T\leq 10^4,n,k\leq10^{10}\)
\(g(q,b)=\left\{\begin{aligned}g(q,b-1)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ q<p_b^2 \\ g(q,b-1)-p_b^k*(g(\lfloor \frac q {p_b} \rfloor , b-1)-g(p_{b-1},b-1)) \ \ \ \ \ \ q\ge p_b^2\end{aligned}\right.\)
#include<bits/stdc++.h>
#define LL long long
LL in() {
char ch; LL x = 0, f = 1;
while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);
for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 1) + (x << 3) + (ch ^ 48));
return x * f;
}
const int maxn = 3e6 + 10;
LL n, k, sqt;
LL a[maxn], g[maxn];
int m, tot, pri[maxn];
int getid(LL x) { return x <= sqt? x : m - n / x + 1; }
unsigned LL getans(LL a, int b) {
if(a < pri[b]) return 0;
unsigned LL ans = (k + 1) * (g[getid(a)] - g[getid(pri[b - 1])]);
for(int i = b; i <= tot && (LL)pri[i] * pri[i] <= a; i++)
for(LL x = pri[i], f = k + 1; x * pri[i] <= a; x *= pri[i], f += k)
ans += (getans(a / x, i + 1) * f + f + k);
return ans;
}
int main() {
for(int T = in(); T --> 0;) {
n = in(), k = in();
sqt = sqrt(n);
tot = m = 0;
for(LL i = 1; i <= n; i = a[m] + 1)
a[++m] = n / (n / i), g[m] = a[m] - 1;
for(int i = 2; i <= sqt; i++)
if(g[i] != g[i - 1]) {
pri[++tot] = i;
LL s = (LL)i * i;
for(int j = m; a[j] >= s; j--)
g[j] -= g[getid(a[j] / i)] - g[i - 1];
}
printf("%llu\n", getans(n, 1) + 1);
}
return 0;
}
SP34096 DIVCNTK - Counting Divisors (general) min_25筛
标签:def 空间复杂度 哪些 get ret sqrt har long color
原文地址:https://www.cnblogs.com/olinr/p/10281511.html