Editorial of Educational Codeforces Round 12

Правка en1, от Edvard, 2016-04-20 19:58:31

665F - Four Divisors

The editorial for this problem is a little modification of the materials from the lecture of Mikhail Tikhomirov Endagorion of the autumn of 2015 in Moscow Institute of Physics and Technology. Thanks a lot to Endagorion for that materials.

Easy to see that only the number of the form p·q and p3 (for different prime p, q) have exactly four positive divisors.

We can easily count the numbers of the form p3 in , where n is the number from the problem statement.

Now let p < q and π(k) be the number of primes from 1 to k. Let's iterate over all the values p. Easy to see that . So for fixed p we should increase the answer by the value .

So the task is ot to find ~--- the number of primes not exceeding , for all p.

Denote pj the j-th prime number. Denote dpn, j the number of k such that 1 ≤ k ≤ n, and all prime divisors of k are at least pj (note that 1 is counted in all dpn, j, since the set of its prime divisors is empty). dpn, j satisfy a simple recurrence:

\begin{itemize}

\item dpn, 1 = n (since p1 = 2)

\item dpn, j = dpn, j + 1 + dpn / pj⌋, j, hence dpn, j + 1 = dpn, j - dpn / pj⌋, j

\end{itemize}

Let pk be the smallest prime greater than . Then π(n) = dpn, k + k - 1 (by definition, the first summand accounts for all the primes not less than k).

If we evaluate the recurrence dpn, k straightforwardly, all the reachable states will be of the form dpn / i⌋, j. We can also note that if pj and pk are both greater than , then dpn, j + j = dpn, k + k. Thus, for each n / i it makes sense to keep only values of dpn / i⌋, j.

Instead of evaluating all DP states straightforwardly, we perform a two-step process:

\begin{itemize}

\item Choose K.

\item Run recursive evaluation of dpn, k. If we want to compute a state with n < K, memorize the query ``count the numbers not exceeding n with all prime divisors at least k''.

\item Answer all the queries off-line: compute the sieve for numbers up to K, then sort all numbers by the smallest prime divisor. Now all queries can be answered using RSQ structure. Store all the answers globally.

\item Run recurisive evaluation of dpn, k yet again. If we want to compute a state with n < K, then we must have preprocessed a query for this state, so take it from the global set of answers.

\end{itemize}

The performance of this approach relies heavily on Q~--- the number of queries we have to preprocess.

{\bf Statement.} .

\begin{proof}

Each state we have to preprocess is obtained by following a dpn / pj⌋, j transition from some greater state. It follows that Q doesn't exceed the total number of states for n > K.

[Q \leq \sum_{j = 1}^{n / K} \pi(\sqrt{n / j}) \sim \sum_{j = 1}^{n / K} \sqrt{n / j} / \log n \sim \frac{1}{\log n}\int_1^{n / K} \sqrt{n / x} dx \sim \frac{n}{\sqrt{K}\log n}]

\end{proof}

The preprocessing of Q queries can be done in , and it is the heaviest part of the computation. Choosing optimal , we obtain the complexity .

C++ solution

Complexity: .

Теги education round 12, editorial

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
ru9 Русский Edvard 2016-04-21 01:56:30 7297
en13 Английский Edvard 2016-04-21 00:46:44 2897
en12 Английский Edvard 2016-04-21 00:24:45 2294
en11 Английский Edvard 2016-04-21 00:12:52 2378
en10 Английский Edvard 2016-04-21 00:02:42 818
en9 Английский Edvard 2016-04-21 00:00:58 1001
en8 Английский Edvard 2016-04-20 23:03:30 65
ru8 Русский Edvard 2016-04-20 23:03:12 112
ru7 Русский Edvard 2016-04-20 22:56:00 68
en7 Английский Edvard 2016-04-20 22:55:17 16
en6 Английский Edvard 2016-04-20 22:54:41 13
ru6 Русский Edvard 2016-04-20 20:48:13 6203
en5 Английский Edvard 2016-04-20 20:20:15 9 Tiny change: 'the number of the fo' -> 'the numbers of the fo'
en4 Английский Edvard 2016-04-20 20:14:31 2
en3 Английский Edvard 2016-04-20 20:13:49 156
en2 Английский Edvard 2016-04-20 20:00:29 8 (published)
en1 Английский Edvard 2016-04-20 19:58:31 6278 Initial revision for English translation
ru5 Русский Edvard 2016-04-20 19:38:18 133
ru4 Русский Edvard 2016-04-20 19:36:17 2945
ru3 Русский Edvard 2016-04-20 19:12:54 68
ru2 Русский Edvard 2016-04-20 17:48:16 117
ru1 Русский Edvard 2016-04-20 17:39:47 6525 Первая редакция (сохранено в черновиках)