您的位置:首页 > 其它

(算法)辗转相除法求最大公约数和最小公倍数

2007-12-11 16:08 330 查看

package com.wangyile.euclidean;




/**//**


* @author wangyile


* @category algorithm


* TODO get the greatest common divider and the least common multiple


* by algorithm of euclidean


*/




public class G_C_D ...{






public static void main(String[] args) ...{


System.out.println(euclideanG_C_D(21 ,14));


System.out.println(euclideanLCM(14 ,21));


}






public static int euclideanG_C_D(int nX ,int nY)...{


int exchange;




while(nY != 0)...{


exchange = nX % nY;


nX = nY;


nY = exchange;


}


return nX;


}






public static int euclideanLCM(int nX ,int nY)...{


return nX*nY/euclideanG_C_D( nX , nY);


}


}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: