LCM ADN GCD

Calculating LCM is based on calculating GCD:

 Get LCM by Euclid algorithm :

int LCM_Euclid(int &n,int &m)
{
if(n==0||m==0) return 0;
int a=n,b=m,k;
while(a%b!=0)
{
a%=b;
swap(a,b);
}
return n*m/b;
}
View Code

 

posted @ 2013-10-06 14:47  光辉灿烂的日子  阅读(84)  评论(0编辑  收藏  举报