Sum of cubes#10683

Sum of cubes (Editorial)

Let's compute the given sum using a loop.

For the maximum value n = 10000 = 10^4, the value n^3 = 10^{12} does not fit into a -bit integer type int. Therefore, it is necessary to use a -bit integer type, such as long long.

Algorithm implementation

Read the input value .

scanf("%lld", &n);

Compute the required sum.

for (i = 1; i <= n; i++)
  sum += i * i * i;

Print the answer.

printf("%lld\n", sum);