Code: Select all
(n & ~highest_one_bit(n)) << 1
Code: Select all
(n & ~highest_one_bit(n)) << 1
Code: Select all
(x-((int) log2(x)))*2
Code: Select all
def f(end):
i = 0
elementsOutput = 0
elementsOutputCounter = 0
act = 0
while i < end:
elementsOutputCounter = 0
while elementsOutputCounter < elementsOutput:
i += 1
act += 2
elementsOutputCounter += 1
if i == end: return act
elementsOutput = elementsOutput * 2 + 1
i += 1
act = 0
if i == end: return act
return act
def schemeFunction(i):
return f(i-1)
print schemeFunction(123456789)
Same idea, but as Maxima expression:outsider wrote:I found this Algo:it means the same, but without bitoperationsCode: Select all
(x-((int) log2(x)))*2
Code: Select all
(x-2^truncate(log(x)/log(2)))*2