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 — [119098252](https://codeforces.com/contest/1538/submission/119098252)↵
↵
Using second method — [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?
↵
`for(u = 2; u <= sqrt(n); u++)`↵
↵
or↵
↵
`for(u = 2; u*u <= n; u++)`↵
↵
Here are my both submission↵
↵
Using first method — [119098252](https://codeforces.com/contest/1538/submission/119098252)↵
↵
Using second method — [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?