dkyu021's blog

By dkyu021, history, 5 days ago, In English

Hello everyone, I hope you all are doing well and are healthy & fit.

I just wanted to ask why am I getting TLE with this submission My Submission, whereas all other codes with same logic and I guess same code structure is accepted, For example

Question Link

I don't know what am I missing in my submission?

Your help is very much appreciated and Thank you in advance.

Update:

  • Yes changing i<=sqrt(n) to i*i<=n is worth changing. But after that also I was getting a TLE!
  • After changing Long Long to int gave me AC.

I get the reason why changing sqrt(n) can decrease time, but what's with changing Long Long to int, how is it contributing to reduce time??

 
 
 
 
  • Vote: I like it
  • +1
  • Vote: I do not like it

»
5 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Use int instead of long long. It worked for me.

»
5 days ago, # |
  Vote: I like it 0 Vote: I do not like it

probably using the sqrt function everytime in the loop increases the time as it calculates the qare root every time of n.change it into i*i<=n then check!

  • »
    »
    5 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Yes it worked but had to change long long to int also

»
5 days ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Your code worked when i<=sqrt(n) was replaced by i*i<=n.

  • »
    »
    5 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    It worked after I changed sqrt() by i*i along with that I had to change long long with int also to get accepted.