@Saurabh: According to the statement of the problem using multiplication is not allowed, but you can replace (1<<k)*b by b<<k to eliminate your multiplications.
Dave On Aug 27, 2:49 am, saurabh modi <[email protected]> wrote: > I think that this code can suffice. > > http://www.ideone.com/ESW8Z > > #include<stdio.h> > > int solve(int,int); > > int main() > { > printf("%d",solve(100,10)); > return 0; > > } > > int solve(int a,int b) > { > int quotient=0,k=0; > if(a<b) > return quotient; > while((1<<k)*b<=a) > { > k++; > } > k--; > quotient=(1<<k)+solve(a-(1<<k)*b,b); > return quotient; > > } > > It also gives correct answer.Plus,its easy to read and concise.it is > O(log(quotient)) solution. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
