Sieve of Sundaram (for finding prime numbers)
Pyth, 23 bytes
2j@JSQmhyd-Jm+sdy*Fd^J2
Demonstration
Really just implements the algorithm as given.
Haskell, 93 90 bytes
import Data.List
g n=unlines[show$2*x+1|r<-[[1..n]],x<-2:(r\\[i+j+2*i*j|j<-r,i<-r]),2*x<n]
How it works: [i+j+2*i*j|j<-r,i<-r]
are all i+j+2ij
which are removed (\\
) from [1..n]
. Scale to 2x+1
and turn them into a string (show
). Join with NL (unlines
).