Skip to content

Conversation

@aastha0326
Copy link

I have added a blog on sieve of eratosthenes, which also has a pseudo java code. Please let me know if you expect any changes and if not merge this PR and add hacktoberfest label on it.

@Ruchip16 Ruchip16 added blog-post for issues that are related to wrting blogs for the community website Hacktoberfest2021 labels Oct 5, 2021
@Ruchip16 Ruchip16 added the dsa label Oct 5, 2021


## Introduction
t is easy to find if some number (say N) is prime or not — you simply need to check if at least one number from numbers lower or equal sqrt(n) is divisor of N. This can be achieved by simple code:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is easy*


But there is great idea — why to "do not check even numbers". This idea can be extended to: "do not divide N by candidate numbers, but mark the prime multiples as 'not prime'".

In other words: if we know about some number p, taht it is prime, we mark all multiples (2*p, 3*p, 4*p, ...) as not a prime. To implement this we need limit (max number we care about), let say it is 120 (because there is nice animation of algorithm on wikipedia).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other words: if we know about some number p, that it is prime, we mark all multiples (2p, 3p, 4*p, ...) as not a prime. To implement this we need a limit (max number we care about), let say it is 120 (because there is a nice animation of the algorithm on Wikipedia). - plz run your blog through Grammarly once it has a lot of grammatical mistakes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(because there is a nice animation of the algorithm on Wikipedia) - this line is not needed


In other words: if we know about some number p, taht it is prime, we mark all multiples (2*p, 3*p, 4*p, ...) as not a prime. To implement this we need limit (max number we care about), let say it is 120 (because there is nice animation of algorithm on wikipedia).

In Java I'm using this code:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

highlight your code using the code-blocks like this 👇

add your code here



## Conclusion
The running time of block sieving is the same as for regular sieve of Eratosthenes (unless the size of the blocks is very small), but the needed memory will shorten to O(n‾√+S) and we have better caching results. On the other hand, there will be a division for each pair of a block and prime number from [1;n‾√], and that will be far worse for smaller block sizes. Hence, it is necessary to keep balance when selecting the constant S. We achieved the best results for block sizes between 104 and 105. No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run your blog through Grammarly once so that the grammatical spelling mistakes are avoided and add your code in code-blocks otherwise it won't look good when the blog will get published

@LoopThrough-i-j
Copy link
Member

Also add yourself, as an author @aastha01chauhan.

@aastha0326
Copy link
Author

@LoopThrough-i-j added my name is authors' file. Please add hackberfest-accepted label too!

@Ruchip16 Ruchip16 removed the dsa label Oct 6, 2021
@Ruchip16
Copy link
Contributor

Ruchip16 commented Oct 6, 2021

@LoopThrough-i-j added my name is authors' file. Please add hackberfest-accepted label too!

plz do the requested changes first & commit them @aastha01chauhan

@aastha0326
Copy link
Author

@Ruchip16 I added the codeblock, checked for grammatical mistakes, and added my name in author, have committed the changes too. Is there anything you expect me change?

@aastha0326
Copy link
Author

Checked for mistakes again and corrected too

@aastha0326
Copy link
Author

@Ruchip16 Please let me know what changes you expect?

@Ruchip16
Copy link
Contributor

Ruchip16 commented Oct 7, 2021

@Ruchip16 Please let me know what changes you expect?

i have already suggested the changes plz commit them

@LoopThrough-i-j
Copy link
Member

@aastha01chauhan, please add yourself to the authors as well, as mentioned in the docs.

After completing changes run:

git add .
git commit -m "Fix: blog on Sieve of Eratosthenes"
git push

@aastha0326
Copy link
Author

@LoopThrough-i-j im working on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blog-post for issues that are related to wrting blogs for the community website

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants