Can you help me with TLE

I am getting TLE which doing this question. Can you help me with this? Do I need to optimize the loop which is in main()?

hi @sakshi_singhal
try this -->

Can you tell me what is the difference between your code and my code in terms of time complexity?

@sakshi_singhal
ur logic is correct only… try using long long int due to the constraints
1 <= n <= 10^18

ok, let me try doing it.

Still I am getting Time limit exceeded

ok, so this method will give TLE only as n can be very large…


go though this lecture… Prateek bhaiya has explained the optimal approach…

ok, will spend some time to look around it. If I will face any issue, I will raise another doubt. Thanks you can resolve it now.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.