Background record of mathematical knowledge:
Any >1 integer can be written in the form of one or more prime factor products, and the prime product factor appears in non-descending order.
Then integer x, y can be labeled as:
X=p1x1p2x2...pmxm
Y=p1y1p2y2...pmym
(Where P1,p2,.... Is the prime number, if the exponent of the necessary prime factor XJ or YJ can be 0)
(1) Greatest common divisor gcd (x, y) =p1min (x1,y1) p2min (x2,y2) ... pmmin (XM,YM)
(2) least common multiple LCM (x, y) =p1max (x1,y1) P2max (x2,y2) ... Pmmax (XM,YM)
(3) It is also possible to obtain: LCM (x, y) *gcd (x, y) =x*y
Calculate gcd (x, y)/function int get_gcd (int x,int y) as above thought;
In fact, if the simple calculation of greatest common divisor and least common multiple can not be so complex, can be from large to small traverse min (x, y) of the number of the first to find a convention is the request.
1 intGET_GCD (intXinty)2 {3 inttemp;4 inti;5 if(x>y)6 {7temp=x;8x=y;9y=temp;Ten } One if(y%x==0) A returnx; - for(i=x/2;i>1; i--) - if(x%i==0) the if(y%i==0) - returni; - return 1; - } + - intGET_LCM (intXinty) + { A return(x*y)/(GET_GCD (x, y)); at}
"C" calculates the greatest common divisor and least common multiple of two integers