Java classic algorithm _ 006 Max. Public approx., Min. Public multiple

Source: Internet
Author: User

Calculate the maximum common divisor and least common multiple of two numbers.
If a natural number A can be divisible by natural number B, A is called a multiple of B, and B is the approximate number of. The common divisor of several natural numbers is called the common divisor of these natural numbers.

The largest common divisor of a common divisor is the maximum common divisor of these natural numbers.

The common multiples of several numbers are called the Public multiples of these numbers. The smallest public multiple is called the minimum public multiples of these numbers.
Formula for calculating the maximum common approx.: F (x, y) = f (y, X % Y) (Y> 0)

Formula for least common multiples: least common multiples = product of two numbers/Maximum number of conventions (reason)

Package WZS. arithmetics; // calculate the maximum common number and the minimum common number of two numbers. // If a natural number A can be divisible by natural number B, it is called a as a multiple of B and B as an appointment number of. The common divisor of several natural numbers is called the common divisor of these natural numbers. // The largest common divisor of a common number is called the maximum common divisor of these natural numbers. // The common multiples of several numbers are called the Public multiples of these numbers. The smallest public multiple is called the least public multiples of these numbers. // F (x, y) = f (y, X % Y) (Y> 0) maximum common divisor // minimum common multiple = product of two numbers/maximum Convention (reason) public class test_wzs6 {public static void main (string [] ARGs) {int x = 28; int y = 12; system. out. println ("maximum common Appointment:" + test_wzs6.f (x, y); system. out. println ("minimum public multiple:" + x * Y/test_wzs6.f (x, y ));} /*** calculate the maximum common divisor * @ Param x * @ Param y * @ return */public static int F (int x, int y) {If (x <0 | Y <0) {system. out. println ("incorrect input. "); Return-1;} If (y = 0) {// system. out. println ("maximum common Appointment:" + x); Return X;} return f (y, X % Y );}}

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.