Public feed #379921

Something

public text v1 · immutable
Raw Edit
·published 2007-03-03 16:44 UTC
rendered paste body
NSieve := Object clone

NSieve nsieve := method(n,
	flags := List clone
	n repeat(flags append(true))

	counter := 0

	for(i, 2, n-1,
		if(flags at(i), 
			for(j, i + i, n-1, i, flags atPut(j, false))
			counter = counter + 1
		)
	)
	
	return counter
)
	

// MAIN
x := 2
z := args at(1) asNumber
if((z != nil) and (z > 0), x = z)


step1 := (2 ** x) * 10000
step2 := (2 ** (x - 1)) * 10000
step3 := (2 ** (x - 2)) * 10000

writeln("Primes up to: ", step1 asString, " ", NSieve nsieve(step1) asString)
writeln("Primes up to: ", step2 asString, " ", NSieve nsieve(step2) asString)
writeln("Primes up to: ", step3 asString, " ", NSieve nsieve(step3) asString)