Skip to content

Commit ee5dbdd

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 78849a7 commit ee5dbdd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

maths/sum_of_squares.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""
22
This script demonstrates the implementation of the sum of squares of the first n natural numbers.
33
4-
The function takes an integer n as input and returns the sum of squares
4+
The function takes an integer n as input and returns the sum of squares
55
from 1 to n using the formula n(n + 1)(2n + 1) / 6. This formula computes the sum efficiently
66
without the need for iteration.
77
88
https://www.cuemath.com/algebra/sum-of-squares/
99
"""
1010

11+
1112
def sum_of_squares(n: int) -> int:
1213
"""
1314
Implements the sum of squares formula for the first n natural numbers.
@@ -25,9 +26,10 @@ def sum_of_squares(n: int) -> int:
2526
>>> sum_of_squares(10)
2627
385
2728
"""
28-
return n * (n + 1) * (2*n + 1) // 6
29+
return n * (n + 1) * (2 * n + 1) // 6
2930

3031

3132
if __name__ == "__main__":
3233
import doctest
34+
3335
doctest.testmod()

0 commit comments

Comments
 (0)