One algorithm per day: Greatest common divisor and least common multiple to find two numbers

Source: Internet
Author: User
Tags greatest common divisor

Greatest common divisor and least common multiple to find two numbers

Answer:

When the larger number is divided by the remainder of the smaller number equals 0 o'clock, the smaller number is greatest common divisor.

The result of multiplying the two numbers by their greatest common divisor is least common multiple.

int cdivisor (int x1,int y1) {int r,temp;if (x1<y1) {Temp =x1;x1 = Y1;y1 = temp;} while (X1%Y1)//When the larger number divided by the remainder of the smaller number equals 0 o'clock, the smaller number is greatest common divisor {r=x1%y1;x1=y1;y1=r;} return y1;} int cmultiple (int x2,int y2,int d1) {return x2*y2/d1;//two multiplication result divided by their greatest common divisor to least common multiple}

  

One algorithm per day: Greatest common divisor and least common multiple to find two numbers

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.