{"id":1194,"date":"2026-05-05T03:25:10","date_gmt":"2026-05-05T03:25:10","guid":{"rendered":"https:\/\/yesrenee.com\/?p=1194"},"modified":"2026-05-09T19:53:12","modified_gmt":"2026-05-09T19:53:12","slug":"the-sieve-of-eratosthenes","status":"publish","type":"post","link":"https:\/\/yesrenee.com\/?p=1194","title":{"rendered":"The Sieve of Eratosthenes"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/image.made-in-china.com\/365f3j00osYiBeMtSFcJ\/Stainless-Steel-Kitchenware-Tool-Flour-Sifter-Pan-Baking-Powdered-Flour-Sieve-Mesh.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>That is a sieve.<\/p>\n\n\n\n<p>I usually use sieves to sift my cake flour. Sifting cake flour means the bulky stuff is forced through these small holes. Thus, the flour ends up fine; finer and softer than sand.<\/p>\n\n\n\n<p>Why must I sift my cake flour? So the finished cake is light as a feather and soft as silk and fluffy as a cotton fiber.<\/p>\n\n\n\n<p>Math also needs sifting sometimes. Why have a bulky, indigestible rock when we can have something as fluffy as a chiffon cake?<\/p>\n\n\n\n<p>2000 years ago, Eratosthenes thought so too. (Actually, chiffon cake was invented 1800 years later, but let&#8217;s not discuss that here.)<\/p>\n\n\n\n<p>How many such primes are there between two given numbers $a$ and $b$?<\/p>\n\n\n\n<p>You could solve this with brute force. Test all the numbers between or equal to $a$ and $b$.<\/p>\n\n\n\n<p>But who wants too? If you had two large numbers, $1000000000$ and $2000000000$, the process would take years!<\/p>\n\n\n\n<p>Eratosthenes knew that too.<\/p>\n\n\n\n<p>He made his own sieve.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Explain what Eratosthenes&#8217; sieve is.<\/h2>\n\n\n\n<p>If you think about it, any composite integer is equal to a prime multiplied by any other integer (prime or composite, it doesn&#8217;t matter, as long as it&#8217;s more than 1).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"438\" height=\"432\" src=\"https:\/\/yesrenee.com\/wp-content\/uploads\/2026\/05\/image.png\" alt=\"\" class=\"wp-image-1197\" srcset=\"https:\/\/yesrenee.com\/wp-content\/uploads\/2026\/05\/image.png 438w, https:\/\/yesrenee.com\/wp-content\/uploads\/2026\/05\/image-300x296.png 300w\" sizes=\"auto, (max-width: 438px) 100vw, 438px\" \/><\/figure>\n\n\n\n<p>$1$ is definitely not prime. $2$ is prime, of course.<\/p>\n\n\n\n<p>Let&#8217;s take all the multiples of $2$ within these boundaries&#8230; that are not $2$ itself, of course!<\/p>\n\n\n\n<p>$4$, $6$, $8$ and so on, until $100$. Let&#8217;s cross them off.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"440\" height=\"432\" src=\"https:\/\/yesrenee.com\/wp-content\/uploads\/2026\/05\/image-1.png\" alt=\"\" class=\"wp-image-1198\" srcset=\"https:\/\/yesrenee.com\/wp-content\/uploads\/2026\/05\/image-1.png 440w, https:\/\/yesrenee.com\/wp-content\/uploads\/2026\/05\/image-1-300x295.png 300w\" sizes=\"auto, (max-width: 440px) 100vw, 440px\" \/><\/figure>\n\n\n\n<p>The next number that isn&#8217;t crossed off is 3, so let&#8217;s cross off all of 3&#8217;s multiples.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"441\" height=\"433\" src=\"https:\/\/yesrenee.com\/wp-content\/uploads\/2026\/05\/image-2.png\" alt=\"\" class=\"wp-image-1199\" srcset=\"https:\/\/yesrenee.com\/wp-content\/uploads\/2026\/05\/image-2.png 441w, https:\/\/yesrenee.com\/wp-content\/uploads\/2026\/05\/image-2-300x295.png 300w\" sizes=\"auto, (max-width: 441px) 100vw, 441px\" \/><\/figure>\n\n\n\n<p>The next number that hasn&#8217;t been crossed off is 5, so let&#8217;s cross off all of its multiples. And let&#8217;s keep going until we can&#8217;t cross any more.<\/p>\n\n\n\n<p>We&#8217;re done with:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"298\" height=\"284\" src=\"https:\/\/yesrenee.com\/wp-content\/uploads\/2026\/05\/image-3.png\" alt=\"\" class=\"wp-image-1200\"\/><\/figure>\n\n\n\n<p>Have you notcied? This removes all of the composite numbers!<\/p>\n\n\n\n<p>Now it&#8217;s easy to count how many primes there are.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How can I implement this in coding?<\/h2>\n\n\n\n<p>First, let&#8217;s try to solve this question:<\/p>\n\n\n\n<p>How many primes are between $a$ and $b$, inclusive?<\/p>\n\n\n\n<p>First, let&#8217;s try a simple case. $a = 1$ and $b = 10$.<\/p>\n\n\n\n<p>Let&#8217;s create a vector array and call it<\/p>\n","protected":false},"excerpt":{"rendered":"<p>That is a sieve. I usually use sieves to sift my cake flour. Sifting cake flour means the bulky stuff is forced through these small holes. Thus, the flour ends up fine; finer and softer than sand. Why must I sift my cake flour? So the finished cake is light as a feather and soft [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1221,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[46,55,22,54],"class_list":["post-1194","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-daily","tag-coding","tag-history","tag-math","tag-number-theory"],"_links":{"self":[{"href":"https:\/\/yesrenee.com\/index.php?rest_route=\/wp\/v2\/posts\/1194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yesrenee.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yesrenee.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yesrenee.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yesrenee.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1194"}],"version-history":[{"count":7,"href":"https:\/\/yesrenee.com\/index.php?rest_route=\/wp\/v2\/posts\/1194\/revisions"}],"predecessor-version":[{"id":1220,"href":"https:\/\/yesrenee.com\/index.php?rest_route=\/wp\/v2\/posts\/1194\/revisions\/1220"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/yesrenee.com\/index.php?rest_route=\/wp\/v2\/media\/1221"}],"wp:attachment":[{"href":"https:\/\/yesrenee.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yesrenee.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yesrenee.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}