REDONE Problem - CodeChef

Hey everyone, i am solving this question but i’m not able to understand why i’m getting TLE, i have submitted atleast 7-8 times.
Link to java submission : - CodeChef: Practical coding for everyone
Link to cpp submission : - CodeChef: Practical coding for everyone

I have checked other accepted solutions, they are more or less same as mine

I looked at your C++ submission. It seems that you are computing the values from 1 to 10^6 for every testcase.
Instead precompute if for once and return the required value.
I also was struggling with same but realised it a bit later.

What you should do is:
Try to compute the vector preco out of solve() function and make it global.

Thanks , it worked.