@Kamus, what?
If rows = columns = deepth = 4, then ans becomes 4*4*4 = 64. But that's not the correct answer, neither is 96. The correct answer is 99.
'Deepth'" (should be 'depth' of course) is not the number of faces. It's the number of cubes in the third dimension.
The correct code should be
n = random.Next(max_random) ans = 0 for i in xrange(2, n + 1): ans += i**3
Alternatively, one can use the closed-form formula to compute the sum: n = random.Next(max_random) ans = (n*(n + 1) / 2)**2 - 1
It should be noted that in the case of unequal dimensions (i. e. rows, cols and depth differ from each other) the task gets a bit harder.
@Kamus, what?
If rows = columns = deepth = 4, then ans becomes 4*4*4 = 64. But that's not the correct answer, neither is 96. The correct answer is 99.
'Deepth'" (should be 'depth' of course) is not the number of faces. It's the number of cubes in the third dimension.
The correct code should be
n = random. Next(max_ random)
ans = 0
for i in xrange(2, n + 1):
ans += i**3
Alternatively, one can use the closed-form formula to compute the sum: Next(max_ random)
n = random.
ans = (n*(n + 1) / 2)**2 - 1
It should be noted that in the case of unequal dimensions (i. e. rows, cols and depth differ from each other) the task gets a bit harder.