Java greatest common divisor least common multiple

Source: Internet
Author: User

/**
* 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.