86827890 problem:https://codeforces.net/contest/1372/problem/B it says TLE on the 4th test case. Can someone please help me to find a better solution.Thanks in advance.
p.s.:sorry if this isn't how you are supposed to use blogs, i wasn't sure where to post doubts in this website.
For odd numbers you are checking till n/2 making the complexity O(n). The constraints are too high for O(n). Try doing it in O(sqrt(n))
thankyou, how will i know if the constraints are too high for my time complexity?
Suppose you know your complexity and it is something like $$$O(f(n))$$$. Take the maximum possible $$$n$$$ and calculate $$$f(n)$$$. If it is less than $$$2 \cdot 10^8$$$ it fits in 1 second (it's only a rule of thumb but in practice it works very well).
In your case maximum value of $$$n$$$ is $$$10^9$$$.
if complexity is $$$O(\sqrt{n})$$$: $$$\sqrt{10^9} \approx 31600 < 2 \cdot 10^8$$$, passes very well.
if complexity is $$$O(n)$$$: $$$10^9 > 2 \cdot 10^8$$$, won't pass unless you try very hard to squeeze it in.
Thankyou very much, the rule of thumb will help me a lot :D
There are several thousend working solutions and a tutorial
You are supposed to have a look into that resources.