# What's wrong with my code for finding primes?

From here I found a fast method to make prime list, the python version works well, but my Mathematica version does not. Obviously ,169 is not a prime number. What's wrong with my program?

'''Python code'''
n = 200
sieve = np.ones(n / 3 + (n % 6 == 2), dtype = np.bool)
sieve[0] = False
for i in xrange(int(n**0.5)/3+1):
if sieve[i]:
k=(3 * i + 1) | 1
sieve[      ((k*k)/3)      :: 2 * k] = False
sieve[(k * k + 4 * k - 2 * k * (i & 1))/3 :: 2 * k] = False
print ((3 * np.nonzero(sieve)[0] + 1) | 1)


(*Mathematica code*)
Clear["*"];
n = 200;
p = ConstantArray[1, Quotient[n, 3] + Boole[Mod[n, 6] == 2]];
p[[1]] = 0;
Do[
If[p[[i]] != 0,
k = BitOr[3 (i - 1) + 1, 1];
p[[Quotient[k^2, 3] + 1 ;; -1 ;; 2 k]] = 0;
p[[Quotient[(k^2 + 4 k - 2 k BitAnd[i - 1, 1]), 3] + 1 ;; -1 ;; 2 k]] = 0;],
{i, 1, Floor[n^0.5]/3}];
res = BitOr[3 (Flatten@SparseArray[p]["NonzeroPositions"] - 1) + 1, 1];
Pick[res, PrimeQ @ res, False]

-
The simple way: Prime[Range[50]] gives the first 50 primes. –  bill s Aug 26 at 17:32
Might I suggest you set your "Notebook's Default Context" to "Unique to this Notebook"? It eliminates some of the need to run Clear["*"];. –  rcollyer Aug 26 at 17:32
@bills,Prime@Range@PrimePi[10^7] // Length on my laptop takes about 3s, that method only need 0.4s. –  expression Aug 26 at 17:41
{i, 1, Floor[n^0.5]/3+2} –  Tobias Hagge Aug 27 at 2:27
explorer, I believe "code-review" is best reserved for critique of working code, though it doesn't say that in the tag wiki. I have replaced the tag with "broken-code" which I think is more accurate. –  Mr.Wizard Aug 27 at 6:43