<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Segmented Sieve Of Eratosthenes</title>
	<atom:link href="http://programmingpraxis.com/2010/02/05/segmented-sieve-of-eratosthenes/feed/" rel="self" type="application/rss+xml" />
	<link>http://programmingpraxis.com/2010/02/05/segmented-sieve-of-eratosthenes/</link>
	<description>A collection of etudes, updated weekly, for the education and enjoyment of the savvy programmer</description>
	<lastBuildDate>Sat, 11 Feb 2012 09:48:16 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: BMeph</title>
		<link>http://programmingpraxis.com/2010/02/05/segmented-sieve-of-eratosthenes/#comment-1148</link>
		<dc:creator><![CDATA[BMeph]]></dc:creator>
		<pubDate>Sat, 10 Apr 2010 07:59:04 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1962#comment-1148</guid>
		<description><![CDATA[Won&#039;t doing &quot;(primes (+ (isqrt r) 1))&quot; sometimes add an extra prime that you won&#039;t need?

For instance, try it with l = 200, and r = 325 (basically, any time r is at least the value of
 an even square, but less than an odd square).]]></description>
		<content:encoded><![CDATA[<p>Won&#8217;t doing &#8220;(primes (+ (isqrt r) 1))&#8221; sometimes add an extra prime that you won&#8217;t need?</p>
<p>For instance, try it with l = 200, and r = 325 (basically, any time r is at least the value of<br />
 an even square, but less than an odd square).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Segmented Sieve Of Eratosthenes &#171; Code and Bugs</title>
		<link>http://programmingpraxis.com/2010/02/05/segmented-sieve-of-eratosthenes/#comment-995</link>
		<dc:creator><![CDATA[Segmented Sieve Of Eratosthenes &#171; Code and Bugs]]></dc:creator>
		<pubDate>Fri, 05 Feb 2010 21:56:02 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1962#comment-995</guid>
		<description><![CDATA[[...] Of&#160;Eratosthenes  February 5, 2010 Mithrandir Leave a comment Go to comments    Today&#8217;s Programming Praxis problem describes an algorithm which may be used to find the prime numbers in a large interval, so large [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Of&nbsp;Eratosthenes  February 5, 2010 Mithrandir Leave a comment Go to comments    Today&#8217;s Programming Praxis problem describes an algorithm which may be used to find the prime numbers in a large interval, so large [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mithrandir</title>
		<link>http://programmingpraxis.com/2010/02/05/segmented-sieve-of-eratosthenes/#comment-994</link>
		<dc:creator><![CDATA[Mithrandir]]></dc:creator>
		<pubDate>Fri, 05 Feb 2010 21:39:46 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1962#comment-994</guid>
		<description><![CDATA[My first try

[sourcecode lang=&quot;css&quot;]
firstQ :: Int -&gt; Int -&gt; Int
firstQ l pk = (-(1+l+pk) `div` 2) `mod` pk

nextQ :: Int -&gt; Int -&gt; Int -&gt; Int
nextQ b pk qk = (qk - b) `mod` pk

sieveBlock :: [Int] -&gt; [Int] -&gt; [Int] -&gt; [Int]
sieveBlock [] [] blk = blk
sieveBlock (p:ps) (o:ofs) blk = filter f (sieveBlock ps ofs blk)
  where
    f x = (x &lt; o) &#124;&#124; ((x - o) `mod` p /= 0)

getValsfromBlock :: Int -&gt; [Int] -&gt; [Int]
getValsfromBlock l bl = map (\x-&gt;l+1+2*x) bl

sieve :: Int -&gt; Int -&gt; Int -&gt; [Int] -&gt; [Int]
sieve l r b primes = middle $ until stop incr start
  where
    middle (_, v, _) = v
    stop (sb, _, _) = sb == r
    start = (l, [], map (firstQ l) primes)
    incr (startblock, primessofar, q) = (nextblock, nextprimes, nextq)
      where
	array = [0 .. b-1]
	nextblock = startblock + 2 * b
	nextprimes = primessofar ++ (getValsfromBlock startblock bl)
	nextq = zipWith (nextQ b) primes q
	bl = sieveBlock primes q array

main = print $ sieve 100 200 10 [3, 5, 7, 11, 13]
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>My first try</p>
<pre class="brush: css;">
firstQ :: Int -&gt; Int -&gt; Int
firstQ l pk = (-(1+l+pk) `div` 2) `mod` pk

nextQ :: Int -&gt; Int -&gt; Int -&gt; Int
nextQ b pk qk = (qk - b) `mod` pk

sieveBlock :: [Int] -&gt; [Int] -&gt; [Int] -&gt; [Int]
sieveBlock [] [] blk = blk
sieveBlock (p:ps) (o:ofs) blk = filter f (sieveBlock ps ofs blk)
  where
    f x = (x &lt; o) || ((x - o) `mod` p /= 0)

getValsfromBlock :: Int -&gt; [Int] -&gt; [Int]
getValsfromBlock l bl = map (\x-&gt;l+1+2*x) bl

sieve :: Int -&gt; Int -&gt; Int -&gt; [Int] -&gt; [Int]
sieve l r b primes = middle $ until stop incr start
  where
    middle (_, v, _) = v
    stop (sb, _, _) = sb == r
    start = (l, [], map (firstQ l) primes)
    incr (startblock, primessofar, q) = (nextblock, nextprimes, nextq)
      where
	array = [0 .. b-1]
	nextblock = startblock + 2 * b
	nextprimes = primessofar ++ (getValsfromBlock startblock bl)
	nextq = zipWith (nextQ b) primes q
	bl = sieveBlock primes q array

main = print $ sieve 100 200 10 [3, 5, 7, 11, 13]
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>

