Y
Hacker News
new
|
ask
|
show
|
jobs
by
maple3142
1929 days ago
Summation from 1 to n:
https://godbolt.org/z/673hTr
clang seems to optimize it to (n-1)(n-2)/2+2n-1, which is O(1).
1 comments
mehrdadn
1929 days ago
Even more trivial: sum from 1 to n, then never use the result. It should get optimized out entirely!
link