Two methods for the maximum number of common appointments

Source: Internet
Author: User
The maximum public factor, also known as the maximum public approx. It refers to the maximum public factor of [n (limit 2) Natural numbers a1, a2,...,. There are usually two representation methods: the largest of all their public factors; if the natural number m is the public factor of the n natural numbers, and any public factor of the n numbers is the factor of m, m is the maximum use factor of n.

The maximum public factor, also known as the maximum public approx. It refers to the maximum public factor of [n (limit 2) Natural numbers a1, a2,...,. There are usually two representation methods:

  • The largest of all their public factors;
  • If the natural number m is the public factor of the n natural numbers and any public factor of the n numbers is the m factor, m is the maximum factor used for the n numbers. The description in China is generally [(a1, a2 ,..., [g. c.d. (a1, a2 ,..., an)].

Euclidean Algorithm (Euclidean Algorithm) (Euclid's Algorithm) is generally referred to as the division of the moving phase for finding the maximum public factor. The algorithm is described as follows:

  1. If a is divided by B, the maximum number of common divisor is B;
  2. Otherwise, the maximum number of common dikes is equal to the number of common dikes of B and a % B.

The code is implemented as follows:

#include 
 
  int Euclidean(int parA, int parB){    if (parB == 0) {        return parA;    } else {        return Euclidean(parB, parA % parB);    }}int main(void){    int intA, intB;    printf("Enter two number to calculate its GCD:\n");    scanf("%d %d", &intA, &intB);    printf("The GCD of %d and %d is %d\n", intA, intB, Euclidean(intA, intB));    return 0;}
 

Or

#include 
 
  int Euclidean(int parA, int parB){    return (!parB)?parA : Euclidean(parB, parA % parB);}int main(void){    int intA, intB;    printf("Enter two number to calculate its GCD:\n");    scanf("%d %d", &intA, &intB);    printf("The GCD of %d and %d is %d\n", intA, intB, Euclidean(intA, intB));    return 0;}
 

Address of this article: http://www.nowamagic.net/librarys/veda/detail/451,welcome.

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.