Sum of Cubes
Time limit0.25sMemory limit1024 MB
Given N, the task prints the sum 1 to N, its square, and the sum of cubes 1 to N.
- Level
Easy1 of 10
- Topics
- Implementation, Math
- Solved
- No attempts yet
Problem
Class taught Eunha the following formula relating the sum of the integers from to and the sum of their cubes.
Eunha found this hard to believe, so she decided to check it by writing code. Print the sum of the integers from to , then the square of that sum, then the sum of the cubes of the integers from to , in that order.
Input
The first line contains an integer .
Output
Print three lines.
- Line 1: the sum .
- Line 2: the square of that sum, .
- Line 3: the sum of cubes .
Hint
The square of is multiplied by itself twice, written . .
The cube of is multiplied by itself three times, written . .