# Min_25 sift learning notes (pseudo)

Recommend blog: Https://blog.csdn.net/qq_ 33229466/article/details/79679027

Below, the understanding of some corners and corners.

By factoring all the numbers, we consider that the number is classified according to the first prime factor and its number (p^e). We find that the sum of this class can extract a f (p^e) by the nature of the product function, that is, the formula will turn into f (p^e) (f (a_)). 1 / p^e) + F (a_) 2 / p^e) +... ) It can be found that the latter part of the formula is a very similar problem. This is probably Min_. 25 the main idea of screening.

Specifically, two summation functions are defined. One summation function (h in Zhu Zhenting's paper and G on most blogs on the Internet) assists another evaluation function (that is, G in G papers, and S in most blogs on the Internet).

The evaluation process of the auxiliary evaluation function is very similar to the process of the Ehrlich sieve, so this method is also called the extended Ehrlich sieve method.

Space use only needs O (\sqrt n), because each recursive form is like (all is the division of downward rounding) n - > n / I, N / I - > n / I / J, and the RGP / g / V can be equivalent to (/ *). Number theory is divided into blocks.

What is the complexity of Zhu Zhenting's thesis?

Here are some mathematical formulas (which should be without pots). The code directly sets those formulas. The template is in Counting Divisors.

Product function: $f (x)$

The requirement is $f (p^e) = \sum_. K a_ K (E) p^k$.

Auxiliary summation function: $h_ K (n, J) = \sum_ {2 \leq I \leq N and (I's least prime factor > p_) J or I is prime number)} i^k$

If $p_ J > \sqrt n$, $h_ K (n, J) = h_ K (n, J - 1)$;

Otherwise, there is $h_. K (n, J) = h_ K (n, J – 1) - p_ J^k (h_) K (\lfloor \frac n{p_) J}\rfloor, J – 1) - h_ K (p_) J – 1, J – 1))$.

In particular, for $j = 0$, there is $h_ K (n, J) = \sum_ {2 \leq I \leq n} i^k$.

Shorthand $h_ K (n) = h_ K (n, J)$$p_ J > \sqrt n$(that is, the auxiliary summation function we do not have at last).

Summation function: $g (n, m) = \sum_ {2 \leq I \leq N and (I's least prime factor > p_) M)} f (I)$

It is known that $g (n, m) = \sum_ K a_ K (1) (H (n) - H (p_) M) + \sum_ {p_ M < p_ J\leq \sqrt N and E \geq 1 and p_ J^{e + 1} \leq n} (f (p_) J^e) g (\lfloor \frac n{p_) J^e}\rfloor, J) + F (p_) J^{e + 1})$

$p_ If 0$is spoken, it will be fine when $0$is processed.

$g (n, 0)$is the requirement.

 #include <cstdio>
#include <cstring>

typedef unsigned long long U64;

const int MAX_ SQRT_ N = 1E5;

struct euler_ Sieve {
static const int MAX_ N = MAX_ SQRT_ N;
bool f[MAX_ N + 10];
int p[MAX_ N + 10];
int p_ N;

inline void operator () (int n) {
memset (F, 0, sizeof f);
p_ N = 0;
for (int i = 2; I < = n; ++i) {
if (f[i]) {
p[++p_ N] = I;
}
for (int j = 1; p[j] * I < = n; ++j) {
f[p[j] * * = = {
f[p[j]; ((%) = = 0); 25_ Sieve {
u64 n;

u64 b[2 * MAX_ SQRT_ N + 10]; / / all possible n / I values are from big to small (crap)
int b_ N, sqrt_ N;
inline int locate (U64 I) {return I < sqrt_ N? B_ N - I + 1: n / I;} / / find b[j] = = I position j

int d0[2 * MAX_ SQRT_ N + 10]; / / store the value of H function, array named personal hobby. The value of the H function is only O (\sqrt n). The location at I is not h (I), but h (b[i])
inline void pre_. Calc () {/ / calculate h function
for (int i = 1; I < = b_) N; ++i) d0[i] = 1 * (b[i] - 1); / / h (b[i], 0), j = 0, it is understood that there is no I minimum quality factor > p_. J "this restriction can be. Here and the following 1 * are represented by i^k (k = 0 (not the input k))
for (int j = 1; (U64) es.p[j] * es.p[j] = = n; ++j) {/ / enumerated prime number (= 1); ++i) {/ / enumerated useful, that is, b[i]
d0[i] = d0[i] - 1 * (d0[locate (b[i] / es.p[j])] d0[locate (es.p[j] - 1)]; / / there must be p[j] - 1 < \sqrt n, so it is bound to find a legal location (not falling within a segment) / / because the value of b[i] is small from the main road, so the order of evaluation is no problem, no additional cache array
}
}
}

u64 f_ is needed. A0_ K;
inline U64 f_ A0 (int E) {return e * f_ A0_ K + 1;}
inline U64 f (int p, int E) {return f_ A0 (E);}

u64 Calc (U64 n, int m) {/ / compute g function
u64 RST =
u64 A0 (1) * (d0[locate (n)] - d0[locate (es.p[m])];
for (int j = m + 1; (U64) es.p[j] * * f = =; ()) = (=); (()) = (1); (()) * (*) = <; = +; = + (=); (+) = ((+)); * ((/ /), +) (+); + ((+) + 1 +);
}

inline U64 operator () (U64 n_) U64 f_ A0_ K_ {
n = n_ ;
f_ A0_ K = f_ A0_ K_
sqrt_ / sub block N = 0; while ((U64) sqrt_). N * sqrt_ N < n) ++sqrt_ N;
b_ N = 0; for (U64 I = 1; I < = n; I = n / (n / I) + 1) b[++b_ N] = n / I; I / processing auxiliary summation function
pre_ Calc (); g / / sum
es.p[0] = 0, d0[b_ N + 1] = 0;
return Calc (n, 0) + 1; / / + 1 is the dump of 1
}
} MNS;

int main () {/ / freopen (" In.in "," R "," stdin ";

int TC; scanf ("%d ", &tc); / / int TC = 1;
es (MAX_) SQRT_ N + 5); / / sieve prime number
while (tc--) {
u64 n, f_ A0_ K; scanf ("%llu%llu", &n, &f_) A0_ K);
printf ("%llu\n", MNS (n, f_). A0_ K);
}

return 0;}

This site uses Akismet to reduce spam reviews. Learn how we process your comment data.