During the latest contest I tried to solve this problem, and even came up with an idea.
But unfortunately after implementation, I have realized that fuctions with long numbers are required to solve this problem, as the answer will be too large even for unsigned long long. But when I implemented long number routines, it started working too slow even on small numbers as input data.
I followed this logic:
<spoiler>
Consider 1101000 (binary) as an input. To sum up all the “adjacent bits” from 1 to 1101000 we may do the following.
We may take each “1” digit in the binary representation of the given number, then replace it with a zero, and the rest of digits right to it may be arbitrary. For example: we take our number 1101000, replace the rightmost “1” with a zero and get 1100xxx, where xxx can be arbitrary binary digits. Then we need to compute the sum of all “adjacent bits” for this xxx. Let's do it via function F(xxx), or better F(3), where 3 is the length of the xxxx…xx stuff where digits may be arbitrary. The F(argument) function is calculated pretty simple (But even its result for F(61) is larger than max unsigned int64!) in a recursive/DP way.
After that, we compute the whole thing for 10xxxxx and, finally, for 0xxxxxx. By “whole thing” I mean summing F(argument) values with some extra hints which are simple.
</spoiler>
But after I have implemented it, I realized that long maths is needed, because answers are too large. But when I implemented long numbers routines, it started working too sloooow. And I stucked. Really stucked.
So, any hint (maybe not the entire solution, just a hint)? I surmise that I am making stuff too complex and it's actually much easier than I think. Is it so?
Thank you guys
