Euclidean Algorithm

Total Page:16

File Type:pdf, Size:1020Kb

Euclidean Algorithm Euclidean algorithm In mathematics, the Euclidean algorithm (also called Euclid's algorithm) is an efficient method for computing the greatest common divisor (GCD), also known as the greatest common factor (GCF) or highest common factor (HCF). It is named after the Greek mathematician Euclid, who described it in Books VII and X of his Elements.[1] The GCD of two numbers is the largest number that divides both of them without leaving a remainder. The Euclidean algorithm is based on the principle that the greatest common divisor of two numbers does not change if the smaller number is subtracted from the larger number. For example, 21 is the GCD of 252 and 105 (252 = 21 × 12; 105 = 21 × 5); since 252 − 105 = 147, the GCD of 147 and 105 is also 21. Since the larger of the two numbers is reduced, repeating this process gives successively smaller numbers until one of them is zero. When that occurs, the GCD is the remaining nonzero number. By reversing the steps in the Euclidean algorithm, the GCD can be expressed as a sum of the two original numbers each multiplied by a positive or negative integer, e.g., 21 = [5 × 105] + [(−2) × 252]. This important property is known as Bézout's identity. The earliest surviving description of the Euclidean algorithm is in Euclid's Elements (c. 300 BC), making it one of the oldest numerical algorithms still in common use. The original algorithm was described only for natural numbers and geometric lengths (real numbers), but the algorithm was generalized in the 19th century to other types of numbers, such as Gaussian integers and polynomials in one variable. This led to modern abstract algebraic notions such as Euclidean domains. The Euclidean algorithm has been generalized further to other mathematical structures, such as knots and multivariate polynomials. The Euclidean algorithm has many theoretical and practical applications. It may be used to generate almost all the most important traditional musical rhythms used in different cultures throughout the world. It is a key element of the RSA algorithm, a public-key encryption method widely used in electronic commerce. It is used to solve Diophantine equations, such as finding numbers that satisfy multiple congruences (Chinese remainder theorem) or multiplicative inverses of a finite field. The Euclidean algorithm can also be used in constructing continued fractions, in the Sturm chain method for finding real roots of a polynomial, and in several modern integer factorization algorithms. Finally, it is a basic tool for proving theorems in modern number theory, such as Lagrange's four-square theorem and the fundamental theorem of arithmetic (unique factorization). If implemented using remainders of long division rather than subtractions, Euclid's algorithm computes the GCD of large numbers efficiently: it never requires more division steps than five times the number of digits (base 10) of the smaller integer. This was proved by Gabriel Lamé in 1844, and marks the beginning of computational complexity theory. Methods for improving the algorithm's efficiency were developed in the 20th century. 1 Concrete example Suppose it is desired to find gcd(1989, 867), i.e. the greatest common divisor of 1989 and 867. If we reduce the larger number by subtracting the smaller one from it, the gcd does not change: So subtract again: Now 867 is no longer the smaller number. Continuing in the same way, we reduce the larger number, now 867, by subtracting the smaller one from it, leaving the gcd unchanged: The first number, 255, is still the smaller one, so again we use it to reduce the larger one: Now 255 is the larger number and we reduce it by subtracting 102 from it: Now 102 is the larger one and we reduce it by subtracting 51 from it: Now we are done: we conclude that gcd(1989,867) = 51. Thus we must have By division, we get 2 When one repeatedly reduces the larger number by subtracting the smaller one from it, thus: then the smallest number at the end, 255, is the remainder that results from dividing 1989 by 867. Thus the algorithm is often described as follows: • Given the problem of finding gcd(1989,867), one replaces the larger number, 1989, by the remainder that results from dividing it by the smaller number, 867, getting • Next one replaces the larger number, 867, by the remainder that results from dividing it by the now-smaller number, 255, getting • Next one replaces the larger number, 255, by the remainder that results from dividing it by the now-smaller number, 102, getting • Next one replaces the larger number, 102, by the remainder that results from dividing it by the now-smaller number, 51, getting • When 0 appears, we are done; the gcd is 51. ******************* ************ 3.
Recommended publications
  • Lesson 19: the Euclidean Algorithm As an Application of the Long Division Algorithm
    NYS COMMON CORE MATHEMATICS CURRICULUM Lesson 19 6•2 Lesson 19: The Euclidean Algorithm as an Application of the Long Division Algorithm Student Outcomes . Students explore and discover that Euclid’s Algorithm is a more efficient means to finding the greatest common factor of larger numbers and determine that Euclid’s Algorithm is based on long division. Lesson Notes MP.7 Students look for and make use of structure, connecting long division to Euclid’s Algorithm. Students look for and express regularity in repeated calculations leading to finding the greatest common factor of a pair of numbers. These steps are contained in the Student Materials and should be reproduced, so they can be displayed throughout the lesson: Euclid’s Algorithm is used to find the greatest common factor (GCF) of two whole numbers. MP.8 1. Divide the larger of the two numbers by the smaller one. 2. If there is a remainder, divide it into the divisor. 3. Continue dividing the last divisor by the last remainder until the remainder is zero. 4. The final divisor is the GCF of the original pair of numbers. In application, the algorithm can be used to find the side length of the largest square that can be used to completely fill a rectangle so that there is no overlap or gaps. Classwork Opening (5 minutes) Lesson 18 Problem Set can be discussed before going on to this lesson. Lesson 19: The Euclidean Algorithm as an Application of the Long Division Algorithm 178 Date: 4/1/14 This work is licensed under a © 2013 Common Core, Inc.
    [Show full text]
  • Primality Testing and Integer Factorisation
    Primality Testing and Integer Factorisation Richard P. Brent, FAA Computer Sciences Laboratory Australian National University Canberra, ACT 2601 Abstract The problem of finding the prime factors of large composite numbers has always been of mathematical interest. With the advent of public key cryptosystems it is also of practical importance, because the security of some of these cryptosystems, such as the Rivest-Shamir-Adelman (RSA) system, depends on the difficulty of factoring the public keys. In recent years the best known integer factorisation algorithms have improved greatly, to the point where it is now easy to factor a 60-decimal digit number, and possible to factor numbers larger than 120 decimal digits, given the availability of enough computing power. We describe several recent algorithms for primality testing and factorisation, give examples of their use and outline some applications. 1. Introduction It has been known since Euclid’s time (though first clearly stated and proved by Gauss in 1801) that any natural number N has a unique prime power decomposition α1 α2 αk N = p1 p2 ··· pk (1.1) αj (p1 < p2 < ··· < pk rational primes, αj > 0). The prime powers pj are called αj components of N, and we write pj kN. To compute the prime power decomposition we need – 1. An algorithm to test if an integer N is prime. 2. An algorithm to find a nontrivial factor f of a composite integer N. Given these there is a simple recursive algorithm to compute (1.1): if N is prime then stop, otherwise 1. find a nontrivial factor f of N; 2.
    [Show full text]
  • Computing Prime Divisors in an Interval
    MATHEMATICS OF COMPUTATION Volume 84, Number 291, January 2015, Pages 339–354 S 0025-5718(2014)02840-8 Article electronically published on May 28, 2014 COMPUTING PRIME DIVISORS IN AN INTERVAL MINKYU KIM AND JUNG HEE CHEON Abstract. We address the problem of finding a nontrivial divisor of a com- posite integer when it has a prime divisor in an interval. We show that this problem can be solved in time of the square root of the interval length with a similar amount of storage, by presenting two algorithms; one is probabilistic and the other is its derandomized version. 1. Introduction Integer factorization is one of the most challenging problems in computational number theory. It has been studied for centuries, and it has been intensively in- vestigated after introducing the RSA cryptosystem [18]. The difficulty of integer factorization has been examined not only in pure factoring situations but also in various modified situations. One such approach is to find a nontrivial divisor of a composite integer when it has prime divisors of special form. These include Pol- lard’s p − 1 algorithm [15], Williams’ p + 1 algorithm [20], and others. On the other hand, owing to the importance and the usage of integer factorization in cryptog- raphy, one needs to examine this problem when some partial information about divisors is revealed. This side information might be exposed through the proce- dures of generating prime numbers or through some attacks against crypto devices or protocols. This paper deals with integer factorization given the approximation of divisors, and it is motivated by the above mentioned research.
    [Show full text]
  • Primality Testing for Beginners
    STUDENT MATHEMATICAL LIBRARY Volume 70 Primality Testing for Beginners Lasse Rempe-Gillen Rebecca Waldecker http://dx.doi.org/10.1090/stml/070 Primality Testing for Beginners STUDENT MATHEMATICAL LIBRARY Volume 70 Primality Testing for Beginners Lasse Rempe-Gillen Rebecca Waldecker American Mathematical Society Providence, Rhode Island Editorial Board Satyan L. Devadoss John Stillwell Gerald B. Folland (Chair) Serge Tabachnikov The cover illustration is a variant of the Sieve of Eratosthenes (Sec- tion 1.5), showing the integers from 1 to 2704 colored by the number of their prime factors, including repeats. The illustration was created us- ing MATLAB. The back cover shows a phase plot of the Riemann zeta function (see Appendix A), which appears courtesy of Elias Wegert (www.visual.wegert.com). 2010 Mathematics Subject Classification. Primary 11-01, 11-02, 11Axx, 11Y11, 11Y16. For additional information and updates on this book, visit www.ams.org/bookpages/stml-70 Library of Congress Cataloging-in-Publication Data Rempe-Gillen, Lasse, 1978– author. [Primzahltests f¨ur Einsteiger. English] Primality testing for beginners / Lasse Rempe-Gillen, Rebecca Waldecker. pages cm. — (Student mathematical library ; volume 70) Translation of: Primzahltests f¨ur Einsteiger : Zahlentheorie - Algorithmik - Kryptographie. Includes bibliographical references and index. ISBN 978-0-8218-9883-3 (alk. paper) 1. Number theory. I. Waldecker, Rebecca, 1979– author. II. Title. QA241.R45813 2014 512.72—dc23 2013032423 Copying and reprinting. Individual readers of this publication, and nonprofit libraries acting for them, are permitted to make fair use of the material, such as to copy a chapter for use in teaching or research. Permission is granted to quote brief passages from this publication in reviews, provided the customary acknowledgment of the source is given.
    [Show full text]
  • Integer Factorization and Computing Discrete Logarithms in Maple
    Integer Factorization and Computing Discrete Logarithms in Maple Aaron Bradford∗, Michael Monagan∗, Colin Percival∗ [email protected], [email protected], [email protected] Department of Mathematics, Simon Fraser University, Burnaby, B.C., V5A 1S6, Canada. 1 Introduction As part of our MITACS research project at Simon Fraser University, we have investigated algorithms for integer factorization and computing discrete logarithms. We have implemented a quadratic sieve algorithm for integer factorization in Maple to replace Maple's implementation of the Morrison- Brillhart continued fraction algorithm which was done by Gaston Gonnet in the early 1980's. We have also implemented an indexed calculus algorithm for discrete logarithms in GF(q) to replace Maple's implementation of Shanks' baby-step giant-step algorithm, also done by Gaston Gonnet in the early 1980's. In this paper we describe the algorithms and our optimizations made to them. We give some details of our Maple implementations and present some initial timings. Since Maple is an interpreted language, see [7], there is room for improvement of both implementations by coding critical parts of the algorithms in C. For example, one of the bottle-necks of the indexed calculus algorithm is finding and integers which are B-smooth. Let B be a set of primes. A positive integer y is said to be B-smooth if its prime divisors are all in B. Typically B might be the first 200 primes and y might be a 50 bit integer. ∗This work was supported by the MITACS NCE of Canada. 1 2 Integer Factorization Starting from some very simple instructions | \make integer factorization faster in Maple" | we have implemented the Quadratic Sieve factoring al- gorithm in a combination of Maple and C (which is accessed via Maple's capabilities for external linking).
    [Show full text]
  • Integer Factorization with a Neuromorphic Sieve
    Integer Factorization with a Neuromorphic Sieve John V. Monaco and Manuel M. Vindiola U.S. Army Research Laboratory Aberdeen Proving Ground, MD 21005 Email: [email protected], [email protected] Abstract—The bound to factor large integers is dominated by to represent n, the computational effort to factor n by trial the computational effort to discover numbers that are smooth, division grows exponentially. typically performed by sieving a polynomial sequence. On a Dixon’s factorization method attempts to construct a con- von Neumann architecture, sieving has log-log amortized time 2 2 complexity to check each value for smoothness. This work gruence of squares, x ≡ y mod n. If such a congruence presents a neuromorphic sieve that achieves a constant time is found, and x 6≡ ±y mod n, then gcd (x − y; n) must be check for smoothness by exploiting two characteristic properties a nontrivial factor of n. A class of subexponential factoring of neuromorphic architectures: constant time synaptic integration algorithms, including the quadratic sieve, build on Dixon’s and massively parallel computation. The approach is validated method by specifying how to construct the congruence of by modifying msieve, one of the fastest publicly available integer factorization implementations, to use the IBM Neurosynaptic squares through a linear combination of smooth numbers [5]. System (NS1e) as a coprocessor for the sieving stage. Given smoothness bound B, a number is B-smooth if it does not contain any prime factors greater than B. Additionally, let I. INTRODUCTION v = e1; e2; : : : ; eπ(B) be the exponents vector of a smooth number s, where s = Q pvi , p is the ith prime, and A number is said to be smooth if it is an integer composed 1≤i≤π(B) i i π (B) is the number of primes not greater than B.
    [Show full text]
  • So You Think You Can Divide?
    So You Think You Can Divide? A History of Division Stephen Lucas Department of Mathematics and Statistics James Madison University, Harrisonburg VA October 10, 2011 Tobias Dantzig: Number (1930, p26) “There is a story of a German merchant of the fifteenth century, which I have not succeeded in authenticating, but it is so characteristic of the situation then existing that I cannot resist the temptation of telling it. It appears that the merchant had a son whom he desired to give an advanced commercial education. He appealed to a prominent professor of a university for advice as to where he should send his son. The reply was that if the mathematical curriculum of the young man was to be confined to adding and subtracting, he perhaps could obtain the instruction in a German university; but the art of multiplying and dividing, he continued, had been greatly developed in Italy, which in his opinion was the only country where such advanced instruction could be obtained.” Ancient Techniques Positional Notation Division Yielding Decimals Outline Ancient Techniques Division Yielding Decimals Definitions Integer Division Successive Subtraction Modern Division Doubling Multiply by Reciprocal Geometry Iteration – Newton Positional Notation Iteration – Goldschmidt Iteration – EDSAC Positional Definition Galley or Scratch Factor Napier’s Rods and the “Modern” method Short Division and Genaille’s Rods Double Division Stephen Lucas So You Think You Can Divide? Ancient Techniques Positional Notation Division Yielding Decimals Definitions If a and b are natural numbers and a = qb + r, where q is a nonnegative integer and r is an integer satisfying 0 ≤ r < b, then q is the quotient and r is the remainder after integer division.
    [Show full text]
  • Decimal Long Division EM3TLG1 G5 466Z-NEW.Qx 6/20/08 11:42 AM Page 557
    EM3TLG1_G5_466Z-NEW.qx 6/20/08 11:42 AM Page 556 JE PRO CT Objective To extend the long division algorithm to problems in which both the divisor and the dividend are decimals. 1 Doing the Project materials Recommended Use During or after Lesson 4-6 and Project 5. ٗ Math Journal, p. 16 ,Key Activities ٗ Student Reference Book Students explore the meaning of division by a decimal and extend long division to pp. 37, 54G, 54H, and 60 decimal divisors. Key Concepts and Skills • Use long division to solve division problems with decimal divisors. [Operations and Computation Goal 3] • Multiply numbers by powers of 10. [Operations and Computation Goal 3] • Use the Multiplication Rule to find equivalent fractions. [Number and Numeration Goal 5] • Explore the meaning of division by a decimal. [Operations and Computation Goal 7] Key Vocabulary decimal divisors • dividend • divisor 2 Extending the Project materials Students express the remainder in a division problem as a whole number, a fraction, an ٗ Math Journal, p. 17 exact decimal, and a decimal rounded to the nearest hundredth. ٗ Student Reference Book, p. 54I Technology See the iTLG. 466Z Project 14 Decimal Long Division EM3TLG1_G5_466Z-NEW.qx 6/20/08 11:42 AM Page 557 Student Page 1 Doing the Project Date PROJECT 14 Dividing with Decimal Divisors WHOLE-CLASS 1. Draw lines to connect each number model with the number story that fits it best. Number Model Number Story ▼ Exploring Meanings for DISCUSSION What is the area of a rectangle 1.75 m by ?cm 50 0.10 ء Decimal Division 2 Sales tax is 10%.
    [Show full text]
  • Basics of Math 1 Logic and Sets the Statement a Is True, B Is False
    Basics of math 1 Logic and sets The statement a is true, b is false. Both statements are false. 9000086601 (level 1): Let a and b be two sentences in the sense of mathematical logic. It is known that the composite statement 9000086604 (level 1): Let a and b be two sentences in the sense of mathematical :(a _ b) logic. It is known that the composite statement is true. For each a and b determine whether it is true or false. :(a ^ :b) is false. For each a and b determine whether it is true or false. Both statements are false. The statement a is true, b is false. Both statements are true. The statement a is true, b is false. Both statements are true. The statement a is false, b is true. The statement a is false, b is true. Both statements are false. 9000086602 (level 1): Let a and b be two sentences in the sense of mathematical logic. It is known that the composite statement 9000086605 (level 1): Let a and b be two sentences in the sense of mathematical :a _ b logic. It is known that the composite statement is false. For each a and b determine whether it is true or false. :a =):b The statement a is true, b is false. is false. For each a and b determine whether it is true or false. The statement a is false, b is true. Both statements are true. The statement a is false, b is true. Both statements are true. The statement a is true, b is false.
    [Show full text]
  • Cracking RSA with Various Factoring Algorithms Brian Holt
    Cracking RSA with Various Factoring Algorithms Brian Holt 1 Abstract For centuries, factoring products of large prime numbers has been recognized as a computationally difficult task by mathematicians. The modern encryption scheme RSA (short for Rivest, Shamir, and Adleman) uses products of large primes for secure communication protocols. In this paper, we analyze and compare four factorization algorithms which use elementary number theory to assess the safety of various RSA moduli. 2 Introduction The origins of prime factorization can be traced back to around 300 B.C. when Euclid's theorem and the unique factorization theorem were proved in his work El- ements [3]. For nearly two millenia, the simple trial division algorithm was used to factor numbers into primes. More efficient means were studied by mathemeticians during the seventeenth and eighteenth centuries. In the 1640s, Pierre de Fermat devised what is known as Fermat's factorization method. Over one century later, Leonhard Euler improved upon Fermat's factorization method for numbers that take specific forms. Around this time, Adrien-Marie Legendre and Carl Gauss also con- tributed crucial ideas used in modern factorization schemes [3]. Prime factorization's potential for secure communication was not recognized until the twentieth century. However, economist William Jevons antipicated the "one-way" or ”difficult-to-reverse" property of products of large primes in 1874. This crucial con- cept is the basis of modern public key cryptography. Decrypting information without access to the private key must be computationally complex to prevent malicious at- tacks. In his book The Principles of Science: A Treatise on Logic and Scientific Method, Jevons challenged the reader to factor a ten digit semiprime (now called Jevon's Number)[4].
    [Show full text]
  • Whole Numbers
    Unit 1: Whole Numbers 1.1.1 Place Value and Names for Whole Numbers Learning Objective(s) 1 Find the place value of a digit in a whole number. 2 Write a whole number in words and in standard form. 3 Write a whole number in expanded form. Introduction Mathematics involves solving problems that involve numbers. We will work with whole numbers, which are any of the numbers 0, 1, 2, 3, and so on. We first need to have a thorough understanding of the number system we use. Suppose the scientists preparing a lunar command module know it has to travel 382,564 kilometers to get to the moon. How well would they do if they didn’t understand this number? Would it make more of a difference if the 8 was off by 1 or if the 4 was off by 1? In this section, you will take a look at digits and place value. You will also learn how to write whole numbers in words, standard form, and expanded form based on the place values of their digits. The Number System Objective 1 A digit is one of the symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9. All numbers are made up of one or more digits. Numbers such as 2 have one digit, whereas numbers such as 89 have two digits. To understand what a number really means, you need to understand what the digits represent in a given number. The position of each digit in a number tells its value, or place value.
    [Show full text]
  • Long Division, the GCD Algorithm, and More
    Long Division, the GCD algorithm, and More By ‘long division’, I mean the grade-school business of starting with two pos- itive whole numbers, call them numerator and denominator, that extracts two other whole numbers (integers), call them quotient and remainder, so that the quotient times the denominator, plus the remainder, is equal to the numerator, and so that the remainder is between zero and one less than the denominator, inclusive. In symbols (and you see from the preceding sentence that it really doesn’t help to put things into ‘plain’ English!), b = qa + r; 0 r < a. ≤ With Arabic numerals and using base ten arithmetic, or with binary arith- metic and using base two arithmetic (either way we would call our base ‘10’!), it is an easy enough task for a computer, or anybody who knows the drill and wants the answer, to grind out q and r provided a and b are not too big. Thus if a = 17 and b = 41 then q = 2 and r = 7, because 17 2 + 7 = 41. If a computer, and appropriate software, is available,∗ this is a trivial task even if a and b have thousands of digits. But where do we go from this? We don’t really need to know how many anthills of 20192 ants each can be assembled out of 400 trillion ants, and how many ants would be left over. There are two answers to this. One is abstract and theoretical, the other is pure Slytherin. The abstract and theoretical answer is that knowledge for its own sake is a pure good thing, and the more the better.
    [Show full text]