multiplication of two nmbers such that there are minimum number of addition operations

Write a recursive method to get the multiplication of two numbers such that there are minimum number of addition operations.

// the number of m is n m>n
int minAdd(int m,int n) {  //modify the name as minAdd(int bigNumber,int smallNumber)   which is clear to understand the meaning
if(n==0) return 0;
if(n==1) return m;

if(m<n) return minAdd(n,m);
int res = minAdd(m,n>>1);
if((n&0x1)==1) {
return res+res+m;
} else {
return res+res;
}
}
int minMulti(int m,int n) {
if(m>n) {
return minAdd(m,n);
} else {
return minAdd(n,m);
}
}

posted @ 2014-09-05 22:28  purejade  阅读(134)  评论(0编辑  收藏  举报