Hi everyone, Please review my submission: https://mirror.codeforces.com/problemset/submission/546/213448834
The logic is exactly the same as that of the person who got the first position in the contest. I'm unable to understand how to change the solution to get AC.
Edit: Changed cout to printf and cin to scanf.








here
testcase == 1e6and for each test case your solve function runs at least5e6time(considering only the outer for loop), so in total your time complexity will be at least1e6 * 5e6 == 5e12which gives TLE. U can not calculate the sieve array every time. Rather pre-calculate the sieve only once before taking any input.Read the code again. Notice that
solveis called exactly once (and thus, sieve runs once). The test cases are solved insidesolvein the last for-loop with $$$n$$$ being number of test cases.Also, OP already solved the problem by changing cin/cout to scanf/printf: 213448834