Max Common multiple

Source: Internet
Author: User
Tags greatest common divisor

Huawei machine questions, have done before, review a little ideas.

//Title Description////the least common multiple of positive integers a and positive integers B is the smallest positive integer value divisible by A and B, and an algorithm is designed to find the least common multiple of the inputs A and B. ////Input Description://enter two positive integers a and B. //////Output Description://outputs A and B of the least common multiple. ////Input Example://5//7////Output Example:// *//maximum common factor, also known as greatest common divisor, the largest common factor, refers to the largest of two or more integers in total. The greatest common divisor of A, B is recorded as (A, b), the same as the greatest common divisor of a,b,c (A,B,C), and the greatest common divisor of multiple integers have the same notation. //There are many methods to find greatest common divisor, such as mass factorization, short division, Euclidean method and subtraction method. The concept corresponding to greatest common divisor is least common multiple, and the least common multiple of a, B is recorded as [A, b]. //understand the solution of greatest common divisor and then solve it by using the relationship between greatest common divisor and maximum common multiple#include <iostream>using namespacestd;intgcdintAintb) {    inttemp;  while(b)/*divide until B is 0.*/{Temp=b; b= a%b; A=temp; }    returnA;}intGCD (intAintb//Recursive Implementation{    returnA%b? GCD (b, a%b): b;}intMain () {intA, B; CIN>> a>>b; cout<< A*B/GCD (A, b) <<Endl; return 0;}

Title Description////Positive integer A and positive integer b least common multiple are the smallest positive integer values that can be divisible by A and B, and an algorithm is designed to find the least common multiple of the inputs A and B. Enter a description://Enter two positive integers a and B. Output Description://least common multiple of output A and B. Input example://5//7////Output Example://35
The maximum common factor, also known as greatest common divisor, is the largest of two or more integers. The greatest common divisor of A, B is recorded as (A, b), the same as the greatest common divisor of a,b,c (A,B,C), and the greatest common divisor of multiple integers have the same notation. There are many methods to find greatest common divisor, such as mass factorization, short division, Euclidean method and subtraction method. The concept corresponding to greatest common divisor is least common multiple, and the least common multiple of a, B is recorded as [A, b].

Max 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.