Skip to content

Instantly share code, notes, and snippets.

@chellem
Last active December 17, 2015 21:10
Show Gist options
  • Save chellem/1cd61ee8aa28cb02b139 to your computer and use it in GitHub Desktop.
Save chellem/1cd61ee8aa28cb02b139 to your computer and use it in GitHub Desktop.
Eratosthenes
Eratosthenes(n){
e[1]:=0
(1) for i:=2 to n do
(2) e[i]:=1
p:=2
(3) while p*2<n do{
j:=p*2
(4) while(j<n)do{
(5) e[j]:=0
j:=j+p
}
(6) repeat
p:=p+1
(7) until e[p]=1
}
(8) return(a)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment