Timelimit exceeded

i tried running the code for prateek loves candy


please check my code and help me why this error is coming

you are getting this error because your code is taking more time than what it is expected to. Use sieves of eratosthenes approach to solve this problem as this approach takes less amount of time

please help time limit error is not resolved