28. Sum of Cubes
Difficulty: easy · Math
Problem
Given a positive integer `n`, print the sum of the cubes of all integers from 1 to `n`, that is `1^3 + 2^3 + ... + n^3`.
Input
A single line containing the integer `n`.
Output
Print the sum.
Example 1
Input: 3 Output: 36
Explanation: 1 + 8 + 27 = 36.
Example 2
Input: 1 Output: 1
Explanation: 1^3 = 1.
Constraints
- 1 <= n <= 10^6
Solutions are judged against 2 sample and 10 hidden tests. Sign in to solve it · All problems