#include <stdio.h>
int main ()
{
int a,b,t,c,m,n;
scanf ("%d%d", &a,&b);
M=a; N=b;
1. Seek greatest common divisor by dividing
/*while (b!=0)
{
c = a%b;
A = b;
b = C;
}
printf ("Greatest common divisor:%d\n", a);//Greatest common divisor
printf ("Least common multiple:%d\n", m*n/a);//least common multiple
*/
2. Phase subtraction. The number of large numbers decreases until they are equal */
/*
while (A! = b)
{
if (a>b)
A = a-B;
Else
b = b-a;
}
printf ("Greatest common divisor:%d\n", a);//greatest common divisor A and B are equal
printf ("Least common multiple:%d\n", m*n/a);//least common multiple
*/
3. Poor lifting method for greatest common divisor (do not judge the size!) )
/*
for (t=a;t>0;t--)
{
if (a%t==0 && b%t==0)
Break
}
printf ("Greatest common divisor:%d\n", t);
printf ("Least common multiple:%d\n", a*b/t);
*/
Multiple numbers of greatest common divisor and least common multiple
/*
Example:
for (i= A; i>0; i--)
if (a%i==0&&b%i==0&&c%i==0) break;
printf ("Greatest common divisor:%d\n", i);
for (i= A;; i++)
if (i%a==0&&i%b==0&&i% c==0) break;
printf ("Least common multiple:%d\n", i)
*/
return 0;
}
Finding common algorithms for greatest common divisor and least common multiple