Which is more efficient in for loop u*u<=n or u<=sqrt(n) ?
Difference between en1 and en2, changed 0 character(s)
Can anyone help me, which is more efficient while using in the for loop?↵

`for(u = 2; u <= sqrt(n); u++)`↵

or↵

`for(u = 2; u*u <= n; u++)`↵

Here are my both submission↵

Using first method &mdash; [119098252](https://codeforces.com/contest/1538/submission/119098252)↵

Using second method &mdash; [119098208](https://codeforces.com/contest/1538/submission/119098208)↵

While using the first method i got TLE but the same code using with the second method got Accepted..↵

I am assuming that method one is calculating `sqrt(n)` again and again and other one is calculating `u*u` again and again then why one is got accepted other one is not.↵

Please tell me the reason behind this? 

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English rebel_roar 2021-06-11 00:15:15 0 (published)
en1 English rebel_roar 2021-06-11 00:14:35 753 Initial revision (saved to drafts)