俄国农民乘法

int RussianMul(int n, int m)
{
int remain = 0;
while(n != 1)
{
// odd
if (n % 2 != 0)
{
n = (n-1)/2;
remain += m;
m *= 2;
}
// even
else
{
n /= 2;
m *= 2;
}
}
return m + remain;
}

posted @ 2008-09-13 22:00  至尊王者  阅读(439)  评论(0编辑  收藏  举报