Improve a given function so that it runs in O(log n) time in C++

C++

🤖 Code Explanation

The code calculates the sum of all numbers from 1 to n. The key to making it run in O(log n) time is the i *= 2 statement, which causes the loop to run in O(log n) time.

More problems solved in C++

Download SpellBox today