Please tell me why every time it is printing -1?

I think you have shared a wrong link, your code has no relation to prime sieve problem.(But anyways why a[-1]=0…???)