Re:Finding divisors of a number with Python (2019)
by periram on Thursday December 08, 2022 @12:24PM
(#33910513)
Also (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
for (int i=0; i<sqrt(n); i++) == for (int i=0; i*i < n; i++)
^2 is monotonic