Sum of Squares
4/7
Square numbers also have a closed-form sum:
1² + 2² + … + n² = n × (n + 1) × (2n + 1) / 6
The result is always an integer, because the product n(n+1)(2n+1) is always divisible by 6.
Overflow awareness: the intermediate product grows like n³. In languages with 32-bit ints, use 64-bit types (long long, long). JavaScript numbers are exact up to 2⁵³, which is plenty for the constraints here.