mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-04-20 20:57:35 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
78849a7437
commit
ee5dbdda82
@ -8,6 +8,7 @@ without the need for iteration.
|
|||||||
https://www.cuemath.com/algebra/sum-of-squares/
|
https://www.cuemath.com/algebra/sum-of-squares/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def sum_of_squares(n: int) -> int:
|
def sum_of_squares(n: int) -> int:
|
||||||
"""
|
"""
|
||||||
Implements the sum of squares formula for the first n natural numbers.
|
Implements the sum of squares formula for the first n natural numbers.
|
||||||
@ -25,9 +26,10 @@ def sum_of_squares(n: int) -> int:
|
|||||||
>>> sum_of_squares(10)
|
>>> sum_of_squares(10)
|
||||||
385
|
385
|
||||||
"""
|
"""
|
||||||
return n * (n + 1) * (2*n + 1) // 6
|
return n * (n + 1) * (2 * n + 1) // 6
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
doctest.testmod()
|
doctest.testmod()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user