Greatest common divisor and least common multiple of primary School Olympiad

Source: Internet
Author: User
Tags greatest common divisor

The knowledge of the mean inequality is still used, as evidenced here:

Knowing the two numbers of greatest common divisor and least common multiple, we knew the product of two numbers. According to the mean inequality, two numbers and a certain two number, and they are two more close to the product of the larger. So when the product is certain, the closer they are and the smaller they are, the more they enumerate.

#include <iostream>#include<cstdio>using namespacestd;intgcd,lcm,a,b,tot,ans=10000000; inlineintGCD (intXinty) {    returny==0? X:GCD (y,x%y);}intMain () {scanf ("%d%d",&gcd,&LCM); Tot=gcd*LCM;  for(intI=1; i*i<=tot;i++)      if(tot%i==0&AMP;&AMP;GCD (i,tot/i) = =gcd) ans=min (ans,i+tot/i); cout<<ans;}

Greatest common divisor and least common multiple of primary School Olympiad

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