{"id":775,"date":"2017-03-24T13:06:31","date_gmt":"2017-03-24T21:06:31","guid":{"rendered":"http:\/\/www.tech.dimprash.com\/?p=775"},"modified":"2017-03-24T13:06:31","modified_gmt":"2017-03-24T21:06:31","slug":"generate-prime-numbers-in-the-1-x-range","status":"publish","type":"post","link":"http:\/\/www.tech.dimprash.com\/?p=775","title":{"rendered":"Generate Prime Numbers in the 1..x range"},"content":{"rendered":"<p><strong>Generate Prime Numbers in the 1..x range.<\/strong> <\/p>\n<p><a href=\"http:\/\/leetcode.com\/2010\/04\/finding-prime-numbers.html\">http:\/\/leetcode.com\/2010\/04\/finding-prime-numbers.html<\/a><\/p>\n<p>\/* Generate a prime list from 0 up to n, using The Sieve of Erantosthenes<br \/>\nparam n The upper bound of the prime list (including n)<br \/>\nparam prime[] An array of truth value whether a number is prime<br \/>\n*\/<\/p>\n<pre>void prime_sieve(int n, bool prime[]) {\r\n  prime[0] = false;\r\n  prime[1] = false;\r\n  int i;\r\n  for (i = 2; i <= n; i++) {\r\n    prime[i] = true;\r\n  }\r\n  int limit = sqrt(n);\r\n  for (i = 2; i <= limit; i++) {\r\n    if (prime[i]) {\r\n      for (int j = i * i; j <= n; j += i)\r\n        prime[j] = false;\r\n    }\r\n  }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Generate Prime Numbers in the 1..x range. http:\/\/leetcode.com\/2010\/04\/finding-prime-numbers.html \/* Generate a prime list from 0 up to n, using The Sieve of Erantosthenes param n The upper bound of the prime list (including n) param prime[] An array of truth value whether a number is prime *\/ void prime_sieve(int n, bool prime[]) { prime[0] = &hellip; <a href=\"http:\/\/www.tech.dimprash.com\/?p=775\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Generate Prime Numbers in the 1..x range<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-775","post","type-post","status-publish","format-standard","hentry","category-algorithms"],"_links":{"self":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/775","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=775"}],"version-history":[{"count":1,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/775\/revisions"}],"predecessor-version":[{"id":776,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/775\/revisions\/776"}],"wp:attachment":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=775"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}