4 ms·
But now you can run into problems with integer overflow. It can be solved: sum(n) = is_even(n) ? n/2 * (n+1) : (n+1)/2 * n because of one n and n+1 will a
by roelschroeven 3y ago
But now you can run into problems with integer overflow. It can be solved:
sum(n) = is_even(n) ? n/2 * (n+1) : (n+1)/2 * n
because of one n and n+1 will always be even. But it show that unfortunately things are often not as straightforward as they first appear.