Inspired by this article. Neat tricks for speeding up integer computations.
Note: cin.sync_with_stdio(false);
disables synchronous IO and gives you a performance boost.
If used, you should only use cin
for reading input
(don't use both cin
and scanf
when sync is disabled, for example)
or you will get unexpected results.
x = x << 1; // x = x * 2