From c132622a4c7c659759c69a999fb4ab4392b6bfc0 Mon Sep 17 00:00:00 2001 From: Tarun Khullar <36921843+roll-no-1@users.noreply.github.com> Date: Thu, 4 Oct 2018 19:58:05 +0530 Subject: [PATCH 1/5] Corrected a typo in the block sieve code Changed is_prime[j] = true to is_prime[j] = false --- src/algebra/sieve-of-eratosthenes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algebra/sieve-of-eratosthenes.md b/src/algebra/sieve-of-eratosthenes.md index b3430c789..7796764f3 100644 --- a/src/algebra/sieve-of-eratosthenes.md +++ b/src/algebra/sieve-of-eratosthenes.md @@ -145,7 +145,7 @@ int count_primes(int n) { if (is_prime[i]) { primes.push_back(i); for (int j = i * i; j <= nsqrt; j += i) - is_prime[j] = true; + is_prime[j] = false; } } From 534db0d0ab57a9c1c703f0f184c722cd9e134b79 Mon Sep 17 00:00:00 2001 From: Tarun Khullar <36921843+roll-no-1@users.noreply.github.com> Date: Fri, 5 Oct 2018 09:53:05 +0530 Subject: [PATCH 2/5] Reduced number of operations in block sieve code Changed max(start_idx, 2) * p to max(start_idx, p) * p. This is done so that we always start from the max. of the smallest multiple of p in the range [l, r] and p * p. It is more beneficial to start from p * p rather than 2 * p as lower multiples of p would have been covered by the smaller prime factors. --- src/algebra/sieve-of-eratosthenes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algebra/sieve-of-eratosthenes.md b/src/algebra/sieve-of-eratosthenes.md index 7796764f3..041a99750 100644 --- a/src/algebra/sieve-of-eratosthenes.md +++ b/src/algebra/sieve-of-eratosthenes.md @@ -156,7 +156,7 @@ int count_primes(int n) { int start = k * S; for (int p : primes) { int start_idx = (start + p - 1) / p; - int j = max(start_idx, 2) * p - start; + int j = max(start_idx, p) * p - start; for (; j < S; j += p) block[j] = false; } From bb9650e9eb2bb7e39308cf56deb580f2d9e84897 Mon Sep 17 00:00:00 2001 From: Tarun Khullar <36921843+roll-no-1@users.noreply.github.com> Date: Sun, 7 Oct 2018 16:26:44 +0530 Subject: [PATCH 3/5] Corrected a mistake in the text explaining block sieve code The text read: "Here we have an implementation that counts the number of primes smaller to n using block sieving" while actually the code counts the number of primes smaller than or equal to n. --- src/algebra/sieve-of-eratosthenes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algebra/sieve-of-eratosthenes.md b/src/algebra/sieve-of-eratosthenes.md index 041a99750..70e317eb2 100644 --- a/src/algebra/sieve-of-eratosthenes.md +++ b/src/algebra/sieve-of-eratosthenes.md @@ -132,7 +132,7 @@ We can work on blocks by turns, i.e. for every block $k$ we will go through all It is worth working on the first block differently: first, all the prime numbers from $[1; \sqrt n]$ shouldn't remove themselves; second, the numbers $0$ and $1$ should be marked as non-prime numbers. While working on the last block it should not be forgotten that the last needed number $n$ is not necessary located in the end of the block. -Here we have an implementation that counts the number of primes smaller than $n$ using block sieving. +Here we have an implementation that counts the number of primes smaller than or equal to $n$ using block sieving. ```cpp int count_primes(int n) { From 7a2c4eef4c1e209b92a9d0bbd4bb1c7cbd909200 Mon Sep 17 00:00:00 2001 From: Tarun Khullar <36921843+roll-no-1@users.noreply.github.com> Date: Mon, 15 Oct 2018 17:05:33 +0530 Subject: [PATCH 4/5] Corrected a typo in the application Two stripes Changed "arrays of with values values" to "arrays of values" in line 1 of this sub topic --- src/algebra/fft.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algebra/fft.md b/src/algebra/fft.md index 0aef07f57..28fa86899 100644 --- a/src/algebra/fft.md +++ b/src/algebra/fft.md @@ -540,7 +540,7 @@ Thus these coefficients are the answer to the problem, and we were still able to ### Two stripes -We are given two Boolean stripes (cyclic arrays of with values values $0$ and $1$) $a$ and $b$. +We are given two Boolean stripes (cyclic arrays of values $0$ and $1$) $a$ and $b$. We want to find all ways to attach the first stripe to the second one, such that at no position we have a $1$ of the first stripe next to a $1$ of the second stripe. The problem doesn't actually differ much from the previous problem. From 9b788b47458492f01948dffc2d847af2b9d9f746 Mon Sep 17 00:00:00 2001 From: Tarun Khullar <36921843+roll-no-1@users.noreply.github.com> Date: Wed, 17 Oct 2018 15:44:10 +0530 Subject: [PATCH 5/5] Made some major changes to All possible scalar products subsection Here are the details and possible reasons for the change: * Changed (k-n-1) th shift to (k-(n-1))th shift. The former evaluates to -1th shift for k = n and is wrong. * Changed cyclic shift to cyclic left shift. I always got confused while reading this since I tend to forget whether it was the left shift or the right shift of b. So, I decided to add it explicitly since others may also face the same problem in the future without this info. * Changed index nos. of k from [n .. 2n-1] to [n-1 .. 2n-2]. Since c[n] == c[2n-1], it might make more sense to start from n-1 since after doing this we get shifts in the increasing order i.e., 0th shift, 1st shift, ... , (n-1)th shift. * Added a note in case anyone wonders about the value at c[2n-1]. --- src/algebra/fft.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/algebra/fft.md b/src/algebra/fft.md index 28fa86899..31c538b93 100644 --- a/src/algebra/fft.md +++ b/src/algebra/fft.md @@ -531,12 +531,13 @@ We have to compute the products of $a$ with every cyclic shift of $b$. We generate two new arrays of size $2n$: We reverse $a$ and append $n$ zeros to it. And we just append $b$ to itself. -When we multiply these two arrays as polynomials, and look at the coefficient $c[n],~ c[n+1],~ c[2n-1]$ of the product $c$, we get: +When we multiply these two arrays as polynomials, and look at the coefficient $c[n-1],~ c[n],~ c[2n-2]$ of the product $c$, we get: $$c[k] = \sum_{i+j=k} a[i] b[j]$$ And since all the elements $a[i] = 0$ for $i \ge n$: $$c[k] = \sum_{i=0}^{n-1} a[i] b[k-i]$$ -It is easy to see that this sum is just the scalar product of the vector $a$ with the $(k - n - 1)$-th cyclic shift. +It is easy to see that this sum is just the scalar product of the vector $a$ with the $(k - (n - 1))$-th cyclic left shift. Thus these coefficients are the answer to the problem, and we were still able to obtain it in $O(n \log n)$ time. +Note here that $c[2n-1]$ also gives us the $n$th cyclic shift but that is the same as the $0$th cyclic shift so we don't need to consider that seperately into our answer. ### Two stripes
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: