To remove all digits left of the rightmost digit one in the binary
representation of some integer what we need to do is this:
ans = no -no
and this is what is exactly asked in this problem of SPOJ:
www.spoj.pl/problems/MZVRK/
#includeiostream
using namespace std;
int main()
{
unsigned long
you need to try something better as limits of A and B are very large :)
you can not run a loop from A to B
i have not tried it but the logic is there will be many nos which will give
the same value and we dont need to calculate for them all explicitply :)
On Fri, Jun 17, 2011 at 2:52 PM, KK
where n is ??
On Fri, Jun 17, 2011 at 3:23 PM, Arpit Sood soodfi...@gmail.com wrote:
i have got AC with O(n)
On Fri, Jun 17, 2011 at 2:59 PM, sunny agrawal sunny816.i...@gmail.comwrote:
you need to try something better as limits of A and B are very large :)
you can not run a loop from A to
lol, i mean in linear time
On Fri, Jun 17, 2011 at 3:27 PM, sunny agrawal sunny816.i...@gmail.comwrote:
where n is ??
On Fri, Jun 17, 2011 at 3:23 PM, Arpit Sood soodfi...@gmail.com wrote:
i have got AC with O(n)
On Fri, Jun 17, 2011 at 2:59 PM, sunny agrawal
but limits of A and B are very large
10^15
how is this possible
am i missing something,
like Max(B-A) = 10^6 or 10^7
On Fri, Jun 17, 2011 at 3:30 PM, Arpit Sood soodfi...@gmail.com wrote:
lol, i mean in linear time
On Fri, Jun 17, 2011 at 3:27 PM, sunny agrawal
hmm may be because of [*result will fit into the 64-bit signed integer type
*.]
but i think it can be done optimally
consider if A = 1
B = 7 (taking an easier case)
so for 001,011,101,111 - 1 = 4*1
for 010,110 - 10 = 2*2
for 100 - 100 = 1*4
something like that
so for each A,B we can calculate