Post Reply 
Sieve of Eratosthenes
12-19-2018, 07:00 PM (This post was last modified: 12-24-2018 01:41 PM by Albert Chan.)
Post: #3
RE: Sieve of Eratosthenes
(12-19-2018 02:30 PM)Eddie W. Shore Wrote:  FOR K FROM 2 TO 7 DO
FOR R FROM 1 TO 7 DO
FOR C FROM 1 TO 7 DO
IF FP(M0(R,C)/K)==0 AND M0(R,C)>K THEN M0(R,C):=0; ...

I don't think the code is really a prime sieve.
A true sieve does not need any divisibility test.
Also, looping count is very high = 6x7x7 = 294

I think sieve should be like below code.
To get your 7x7 matrix, do list2mat(sieve(7*7), 7)

PHP Code:
sieve(n) := {
    
local acppmax;
    
:= range(1n+1); a(1) := 0;       // 1 is not prime
    
pmax := floor(sqrt(n));
    for 
p from 2 to pmax do
        if (
a(p) == 0) continue;         // skip composite
        
for(c:=p*pc<=nc+=pa(c):=0// mark composite
    
end;
    return 
a;

Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Sieve of Eratosthenes - Eddie W. Shore - 12-19-2018, 02:30 PM
RE: Sieve of Eratosthenes - grsbanks - 12-19-2018, 03:24 PM
RE: Sieve of Eratosthenes - Albert Chan - 12-19-2018 07:00 PM
RE: Sieve of Eratosthenes - Thomas Klemm - 12-20-2018, 06:19 AM



User(s) browsing this thread: 1 Guest(s)