Skip to content

The `cubed_sum` calculates the sum of cubes for a specified range.

Notifications You must be signed in to change notification settings

easai/cubed_sum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cubed_sum

The cubed_sum calculates the sum of cubes for a specified range. The naive implementation is just adding cubed numbers. The time complexity is O(n). A more efficient method would involve using the mathematical formula for the sum of cubes, which can compute the result in constant time O(1).

The definition of the sum of cubes and related formulas: The sum of cubes

Additinally, the cubed_sum can calculates the even and odd sums of cubes.

Installation

Clone the repository.

git clone https://github.com/easai/cubed_sum.git

Go to the installed directory, and run poetry install.

poetry install

Test

Run poetry run pytest to run the pytest file.

poetry run pytest

Usage Example

Calculate the sum of cubes of all numbers in a range by calling cubed_sum() method. The parity is set to both even and odd (Parity.BOTH) by default.

print(cubed_sum(1, 5, parity=Parity.BOTH))  # Sum of cubes of all numbers from 1 to 5
print(cubed_sum(1, 5, parity=Parity.EVEN))  # Sum of cubes of even numbers from 1 to 5
print(cubed_sum(1, 5, parity=Parity.ODD))  # Sum of cubes of odd numbers from 1 to 5

About

The `cubed_sum` calculates the sum of cubes for a specified range.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published