Hi everyone, Please review my submission: https://codeforces.me/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 == 1e6
and for each test case your solve function runs at least5e6
time(considering only the outer for loop), so in total your time complexity will be at least1e6 * 5e6 == 5e12
which 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
solve
is called exactly once (and thus, sieve runs once). The test cases are solved insidesolve
in 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
you can try adding ios_base::sync_with_stdio(0); cin.tie(0); right inside your main
example:
int main(){
}
with this you still use cin and cout but its much faster
I had tried that. It still gave TLE for this particular solution.
no it passes, i only changed endl to '\n' and ran with C++20
https://codeforces.me/contest/546/submission/213526500