Moving Phase division-Euclidean Algorithm

Source: Internet
Author: User
Calculate the maximum common divisor of two numbers by moving phase division: the code is as follows:
#include<iostream.h>int gcd(int a,int b){  int temp;  int remainder;  //if necessary,exchange a and b  if(a<b)  {    temp=a;a=b;b=temp;  }remainder=a%b;while(remainder!=0){   a=b;   b=remainder;   remainder=a%b;}return b;}int main(){   int x,y;   int fac;   cout<<"Please enter two integers:";  cin>>x>>y;  fac=gcd(x,y);  cout<<"The greaterest common divisor of";  cout<<x<<"and"<<y<<"is:"<<fac<<endl;return 0;}

In mathematics,Phase Division, Also knownEuclidean Algorithm, Is the algorithm for finding the maximum public approx. The moving phase division first appeared in Euclidean's ry original (Volume VII, proposition I and II). In China, it can be traced back to the 9-Chapter arithmetic in the Eastern Han Dynasty.

The maximum common divisor of two integers (also known as the common factor) is the maximum positive integer that can divide them at the same time. The division of moving phases is based on the following principle: the maximum common divisor of two integers is equal to the maximum common divisor of the two integers. For example, the maximum public approx. of 252 and 105 is 21 (252
= 21 × 12; 105 = 21 × 5); Because 252 − 105 = 147, the maximum number of public appointments between 147 and 105 is also 21. In this process, a large number is reduced, so continuing to perform the same calculation can reduce the two numbers until one of them becomes zero. At this time, the remaining number that has not been changed to zero is the maximum common divisor of two numbers. The Division can also be introduced by the moving phase. The maximum common divisor of two numbers can be expressed by an integer multiple of two numbers, for example, 21.
= 5 × 105 + (−2) × 252. This important equation is called the bezu equation.

The moving phase division first appeared in Euclidean ry (around 300 BC), so it was the first algorithm that is still in use. This algorithm was originally used only to process natural numbers, but in the 19th century, the moving phase division was extended to other types of numbers, such as Gaussian integers and polynomial. Since then, modern abstract algebra concepts such as Euclidean integral rings have emerged. Later, the moving phase division was extended to other mathematical fields, such as knots theory and multivariate polynomials.

There are many applications in the division of moving phase, which can even be used to generate the rhythm of traditional music in different cultures around the world.[1] In modern cryptography, it is an important part of RSA algorithm (a public key encryption algorithm widely used in e-commerce. It is also used to solve the lost graph equation, to find numbers that satisfy the Chinese Remainder Theorem, or to calculate the reciprocal of Finite Fields. The moving phase division can also be used to construct the continuous score. It is also used in the Shi tumm theorem and Some integer decomposition algorithms. The moving phase division is a basic tool in modern number theory.

It is very efficient to process large numbers by moving and division, and the steps required will not exceed five times the number of decimal digits (in decimal. Gabriel lamei
Lam é) proved this in 1844 and created a theory of computing complexity.

Calculate the maximum common divisor of two numbers:

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.