Skip to main content

TCS

TCS OA-26 2024

Problem Description

Given two integers n and m, find the sum of the cubes of all integers from n to m, inclusive. The function should handle cases where n is greater than m and treat n as the starting point and m as the ending point of the range.

Input Format

The first line contains two integers, n and m.

Output Format

Print an integer representing the sum of cubes of all integers in the range [n,m] inclusive.

Constraints

  • 1 ≤ n,m ≤ 50

Example

Sample Input:

1 3

Sample Output:

36

Explanation:

  • The numbers in the range [1,3] are 1, 2, and 3.
  • Their cubes are 1³=1, 2³=8, and 3³=27.
  • Sum of cubes: 1+8+27=36.