C USES division to find the smallest common divisor of two Numbers

  • 2020-05-10 18:33:27
  • OfStack

The greatest use of division is to find the greatest common divisor of two Numbers.

    USES (a,b) to represent the largest common divisor of a and b.

    has a theorem: given that a,b and c are positive integers, if a is divided by b and c remains, then (a,b) =(b,c). (please refer to other materials for proof)

Example: find the greatest common divisor between 15750 and 27216.

    solution:

For now, make sure that the situation continues to develop. Now, 27216=15750×1+11466 eal (15750, 27216) = (15750, 11466)
Remnants of the loop (15750, 11466×1+4284  ) (15750, 11466) =(11466,4284)
Remnants of the earthquake: 11466=4284×2+2898   piece (11466,4284)= (4284, 2898)
Making a eal (4284) =2898×1+1386     (4284, 2898) = (2898, 1386)
Make sure that the situation continues as far as possible; make sure that the situation continues as far as possible; make sure that the situation continues as far as possible; make sure that the situation continues as far as possible; make sure that the situation continues as far as possible; make sure that the situation continues as far as possible; make sure that the situation continues as far as possible;
Around 1386=126×11         eal (1386, 126) =126

    so (15750,27216) is equal to 126

  division is a good method for finding the greatest common divisor between two large Numbers.

The code is as follows:


#include<stdio.h>
int main()
{
  int a,b,temp,x;
  scanf("%d%d",&a,&b);
  if(a>b)
  {
    temp=b;
    b=a;
    a=temp;
  }
  while(b%a!=0)
  {
    x=b%a;
    b=a;
    a=x;
  }
  printf("%d",a);
}

Related articles: