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);
}
}
/**/ /**
* @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);
}
}