Motivation/Original post
Code
So according to you how much time should the above code take ? Well this is what
Custom invocation says
After some googling I figured that there is something called compiler optimization which is why c++20 is taking lesser time, haven't figured out yet what really those optimizations are but will learn in future.
Lesson learned :-
- Use C++20 for submission.
- cout is heavy operation, think for it when limit is tight.
I don'nt know the exact reason for that but that is because your code runs on the edge of time limit so i think it's because every compiler have a different time for processing constants and dealing with stl.
10^8 solutions taking under a second or two can happen, but your code has to be optimized pretty well. The intended solution here is O(tsqrt(n)).
assumptions are dangerous, you should not submit a solution that you think will barely pass TL, it is a bad idea as you didn't factor in the constant factor, etc... therefore always try to write an optimized solution
Auto comment: topic has been updated by Brok3nDreams (previous revision, new revision, compare).
I don't understand the time complexity shown in my submission. I have my submission with pretty much similar time complexity and logic as yours and my compiler too is C++17. But still, mine passed system tests and it shows the time as 0ms. Please can someone explain this? My submission : 192307776
Your solution is O(sqrt(N)), mine is O(N).
No, your c++17 submission is 32 bit, while c++20 is 64 bit. Submitting c++17 with 64 bit compiler is also AC 192379888
Any possible reason why 64bit is faster ?
You use long longs in your code (when you do #define int long long). I'm not sure of the exact operations, but to my understanding 32-bit implementations do operations with long longs by first deconstructing them to 32-bit integers then combining those together, while 64-bit can do the entire operation in one go.