Interesting that in the initialization loop it sets A[0 - 1] to true, yet in your blocky code it appears to be iterating from 0 to n. In fact it always seems to be offsetting by one in array access ... 1 based indexing maybe?
As an aside, Lua also uses 1-based indexing.
Unsurprisingly, it still works (it just loops a few too many times).