'long long' is not the problem.
- Code: Select all
If the value of 'n' is big, like 1000000001, then you have to use this loop for (1000000001/2) times. Which is too big. Try to figure out the last odd number in a certain line. You dont have to use any loop. You can find a general formula. Then the result can be found in just O(1) time, which means no loop. Hope you can generate the formula.