Let's compute the given sum using a loop.
Initialize the sum variable, for example .
Run a loop with from to : at each iteration, add i^3 to .
After the loop finishes, print the .
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);