You add 'i' to 'nums' every time it cannot be divided by any previous number. So '4' is added because it cannot be divided by '3'. '5' is added 3 times because it cannot by divided by '2', '3' nor '4', '6' is added 4 times because it cannot be divided by '4' (1 occurrence) nor '5' (3 occurrences). So actually what your algorithm does is adding all the numbers multiple times approximately doubling size of 'nums' array on every number.
So there are two answers:
it doesn't work as you would expect because you add to nums 'when any' instead of 'when all'
it crashes because it would require array with 2^100 elements (that's a lot of memory).