/**
* Commondiviser.java
* @author: Wang Chao
* March 15, 2017
* Wangchaopa Internship practice. com. greatest common divisor and least common multiple. Commondiviser
* Copyright (c), Infopower Corporation All rights Reserved.
*/
Package Wangchaopa Internship Practice. com. greatest common divisor and least common multiple;
Import Java.util.Scanner;
/**
* O
*
*
* <p>
* Enter two positive integers m and N to find the largest number of conventions and least common multiple
* </p>
*
* @author Wang Chao
* @since 1.0
* @date March 16, 2017 11:08:18
* @see New | modify | Give up
* @see Wangchaopa Internship practice. com. greatest common divisor and least common multiple. Commondiviser: How to divide the method, if N>m 1: if n%m = =
* 0 M is greatest common divisor otherwise n%m=k n=m,m=k Repeat step 1 until the remainder is 0 max common multiple =n*m/greatest common divisor
*/
public class Commondiviser
{
private static Scanner input = new Scanner (system.in);
public static void Main (string[] args)
{
int n = input.nextint ();
int m = Input.nextint ();
int zdgys = result (n, m);
System.out.println ("Greatest common divisor is:" + zdgys);
SYSTEM.OUT.PRINTLN ("Max Common multiple is:" + n * m/zdgys);
Input.close ();
}
public static int result (int n, int m)
{
Remainder
int k = 0;
Make N>m
if (n < m)
{
int t = 0;
t = N;
n = m;
m = t;
}
Until the remainder is 0
while (M! = 0)
{
k = n% m;
n = m;
m = k;
}
SYSTEM.OUT.PRINTLN (n);
return n;
}
}
Java greatest common divisor least common multiple