I think everybody must be having same problem in Problem D having time limit exceeded on Test case 15. The time limit is too strict for the problem. I am tired of optimizing it further now and I have seen exactly same logic being accepted. I am tired and frustrated now. Somebody pls tell how to optimize it from here on.
Here is my Code:
(https://mirror.codeforces.com/contest/1499/submission/110388552)
Auto comment: topic has been updated by dominator1234 (previous revision, new revision, compare).
Auto comment: topic has been updated by dominator1234 (previous revision, new revision, compare).
Auto comment: topic has been updated by dominator1234 (previous revision, new revision, compare).
Just few modifications in your code and it passed in 1044ms.
Code : https://mirror.codeforces.com/contest/1499/submission/110397614
I see so declaring a map do the job. Yeah I thought of that then I just ignored that diff will be not so much in worst case.
Can anyone guide me how I can optimize this code. Luckily it just got accepted (Time : 1996 ms).
Link to my code ( Practice )
https://mirror.codeforces.com/contest/1499/submission/110399006
Small optimization of your code.
Also applying sieve in O(n) will help.