3 ms·
why would you check excess numbers instead of just checking n^2 < end for (int i=0; i<sqrt(n); i++) == for (int i=0; i*i < n; i++) ^2 is monotonic
by nh23423fefe 4y ago
why would you check excess numbers instead of just checking n^2 < end
for (int i=0; i<sqrt(n); i++) == for (int i=0; i*i < n; i++)
^2 is monotonic
- periram 4y agoAlso (n+1)^ = n^2 + 2n +1 i.e. you can have the previous square and just add 2n+1 to it to get the next square (which is 3 additions in total). square += i + i + 1 if square < n; break