Hi,

we can show that

(x/3)  = (x/2) - (x/4) + (x/8) - (x/16) + .... infinity

Proof:
let s1 = (x/2)+(x/8)+(x/32)+...infinity = (x/2)/(1-(1/4))   [Geometric 
Progression , common Ratio(r) = 1/4]
& s2 = (x/4)+(x/16)+(x/64)+...infinity = (x/4)/(1-(1/4))   [Geometric 
Progression , common Ratio(r) = 1/4]

now s1-s2 upon simplifying becomes (x/3)

Implementation:

x1=x>>1;
x2=x>>2;
s1=x1;
s2=x2;
while(x1 || x2){
  s1+=x1>>2;
  s2+=x2>>2;
  x1>>=2;
  x2>>=2;
}
return s1-s2;

If the number is not divisible by 3 the answer returned is the least integer 
function of (x/3)
correct me if i am wrong...

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/YZjVTMk5JvEJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to