Math Fundamentals18 sections · 814 units
Open in Course

Perfect Squares - Iterating Squares

Loop bounds from sequence

For a given ii, which perfect squares should you try? All k2k^2 where k2ik^2 \leq i.

Solving k2ik^2 \leq i gives kik \leq \sqrt{i}. So loop kk from 11 to i\lfloor \sqrt{i} \rfloor.

This comes from algebra: isolating the variable in an inequality. Recognizing the sequence structure (perfect squares) guides your loop design.