mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +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
32634eff5a
commit
7800f1e645
|
@ -1,9 +1,9 @@
|
||||||
#Reeka
|
# Reeka
|
||||||
def sum_of_ap_series(a: int, d: int, n: int) -> int:
|
def sum_of_ap_series(a: int, d: int, n: int) -> int:
|
||||||
"""
|
"""
|
||||||
Calculates the sum of the first 'n' terms of an arithmetic progression (AP)
|
Calculates the sum of the first 'n' terms of an arithmetic progression (AP)
|
||||||
series with the first term 'a' and common difference 'd'.
|
series with the first term 'a' and common difference 'd'.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
a (int): The first term of the AP.
|
a (int): The first term of the AP.
|
||||||
d (int): The common difference between terms.
|
d (int): The common difference between terms.
|
||||||
|
@ -34,7 +34,9 @@ def sum_of_ap_series(a: int, d: int, n: int) -> int:
|
||||||
"""
|
"""
|
||||||
if n <= 0:
|
if n <= 0:
|
||||||
raise ValueError("Number of terms 'n' must be a positive integer")
|
raise ValueError("Number of terms 'n' must be a positive integer")
|
||||||
|
|
||||||
# Formula for the sum of an AP series: S_n = n/2 * (2a + (n-1) * d)
|
# Formula for the sum of an AP series: S_n = n/2 * (2a + (n-1) * d)
|
||||||
return n * (2 * a + (n - 1) * d) // 2
|
return n * (2 * a + (n - 1) * d) // 2
|
||||||
#Reeka
|
|
||||||
|
|
||||||
|
# Reeka
|
||||||
|
|
Loading…
Reference in New Issue
Block a user