Write a function named sumofcubes that takes a single


Challenge Problem 1.

Write a function named sumOfCubes that takes a single integer parameter, n, and returns the number of triplets of positive perfect cubes whose sum is less than or equal to n.

For example, let n = 10. The triplets of positive perfect cubes whose sum is less than or equal to 10 are

1, 1, 1

1, 1, 8

Therefore, sumOfCubes(10) = 2.

This problem also has a performance requirement: When n = 1,000,000 sumOfCubes must return the answer in less than one minute.

sumOfCubes Challenge Problem 2.

We measure the efficiency (or conversely, the cost) of an algorithm by the number of times that some key operation is performed. In this case, the comparison between a sum of three cubes and the parameter n is the likely measure.

Extend your solution to Problem 1 to count the number of comparisons.

Revise your solution to try to minimize the number of comparison.

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: Write a function named sumofcubes that takes a single
Reference No:- TGS02512072

Now Priced at $10 (50% Discount)

Recommended (90%)

Rated (4.3/5)