Sieve[M_] := ( inlist = Range[2, M]; primelist = {}; For[k = 1, (p = inlist[[1]]) <= Sqrt[M], k++, primelist = Append[primelist, p]; inlist = Complement[inlist, p*Range[1, M/p]]; ]; primelist = Union[primelist, inlist] )This program was written by Nick Brooke and it incorporates a few features that are improvements over the program I gave in problem 2 of MATHEMATICA assignment #2. Two of those improvements are: (i) the for-loop is terminated as soon as the minimum value in the list "inlist" exceeds the square root of M, and (ii) it defines p as the first element of "inlist" rather than the minimum value of "inlist" (this saves on computation time and works because the elements of "inlist" are always in increasing order). Note that Nick has also defined the output as a function of M, so just typing "Sieve[10^6]" (for example) will return a list with all the primes up to one million.
If you want to load LaTeX onto your own PC, I recommend using the TeX/LaTeX package called MikTeX bundled with the ASCII editor TeXnicCenter (which is specially designed to work with MikTeX). Together these provide a very nice platform for working in LaTeX, and both programs are entirely free. You can download these programs:
Math 4513, Fall 2004
URL: http://math.ou.edu/~amiller/4513/index.html