4 ms·
Summation from 1 to n: https://godbolt.org/z/673hTr https://godbolt.org/z/673hTr clang seems to optimize it to (n-1)(n-2)/2+2n-1, which is O(1).
by maple3142 6y ago
Summation from 1 to n: https://godbolt.org/z/673hTr https://godbolt.org/z/673hTr
clang seems to optimize it to (n-1)(n-2)/2+2n-1, which is O(1).
- mehrdadn 6y agoEven more trivial: sum from 1 to n, then never use the result. It should get optimized out entirely!