-
Notifications
You must be signed in to change notification settings - Fork 42
Added blog on Sieve of Eratosthenes #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
|
||
|
|
||
| ## 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: |
There was a problem hiding this comment.
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). |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
|
Also add yourself, as an author @aastha01chauhan. |
|
@LoopThrough-i-j added my name is authors' file. Please add hackberfest-accepted label too! |
plz do the requested changes first & commit them @aastha01chauhan |
|
@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? |
|
Checked for mistakes again and corrected too |
|
@Ruchip16 Please let me know what changes you expect? |
i have already suggested the changes plz commit them |
|
@aastha01chauhan, please add yourself to the authors as well, as mentioned in the docs. After completing changes run: |
|
@LoopThrough-i-j im working on it |
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.