Sieve code is not working

it says time limit exceeded