File tree 1 file changed +6
-3
lines changed
1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 1
1
"""
2
- This script demonstrates the implementation of the sum of squares of the first n natural numbers.
2
+ This script demonstrates the implementation of the
3
+ sum of squares of the first n natural numbers.
3
4
4
5
The function takes an integer n as input and returns the sum of squares
5
- from 1 to n using the formula n(n + 1)(2n + 1) / 6. This formula computes the sum efficiently
6
+ from 1 to n using the formula n(n + 1)(2n + 1) / 6.
7
+
8
+ This formula computes the sum efficiently
6
9
without the need for iteration.
7
10
8
11
https://www.cuemath.com/algebra/sum-of-squares/
11
14
12
15
def sum_of_squares (n : int ) -> int :
13
16
"""
14
- Implements the sum of squares formula for the first n natural numbers.
17
+ Implements the sum of squares formulafor the first n natural numbers.
15
18
16
19
Parameters:
17
20
n (int): A positive integer representing the limit of the series
You can’t perform that action at this time.
0 commit comments