Problem with code

used same approach but wrong answer.

my solution:
AC solution:


you are using types with not enought precision to represent results.
I changed Init value of accumulate to (int64_t). result of operation will then also be 64 bit integer.
Also i change datatype for sum from float to double to have more significant bits available.
Afterwards the code gets accepted.

1 Like