Greatest Common Divisor GCD Programming - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Greatest Common Divisor GCD Programming

Description:

Jonas Tan. jonastan_at_cs.tamu.edu. 2006 Summer - Greatest Common Divisor (GCD) Programming ... A common divisor is a positive integer can be a factor of two ... – PowerPoint PPT presentation

Number of Views:288
Avg rating:3.0/5.0
Slides: 9
Provided by: student1
Category:

less

Transcript and Presenter's Notes

Title: Greatest Common Divisor GCD Programming


1
Greatest Common Divisor (GCD) Programming
  • Jonas Tan
  • jonastan_at_cs.tamu.edu

2
Common Divisor
  • A common divisor is a positive integer can be a
    factor of two positive integers, a and b.
  • Example
  • The common divisors of 12 and 18 are 1, 2, 3, 6.

3
Greatest Common Divisor
  • The GCD of two integers, a and b, is the largest
    positive integer that divides both a and b.
  • Example
  • gcd(12, 18) 6
  • gcd(-15, 5) 5

4
Euclidean Algorithm
  • Euclidean algorithm is an efficient and simple
    way to calculate GCD.
  • Theorem
  • Let a and b be positive integers, and r the
    remainder. When a is divided by b. Then (a, b)
    (b, r).

5
Proof of Euclidean Algorithm
  • Let d (a, b) and d (b, r). To prove d d,
    it suffices to show that dd and dd.
  • a bq r (1)
  • Show dd
  • d (a, b) gt da and db gt d(a-bq).
  • In other words, dr by (1).
  • Thus, db and dr, so d(b,r) that is, dd.
  • Show dd
  • d (b, r) gt db and dr gt d(bqr).
  • In other words, da by (1).
  • Thus, db and da, so d(a,b) that is, dd.
  • gt d d, that is, (a, b) (b, r)

6
Euclidean Algorithm
7
Example
  • gcd(68, 26)
  • gcd(16, 10)
  • gcd(10, 6)
  • gcd(6, 4)
  • gcd(4, 2)
  • gcd(2, 0)
  • Therefore, gcd(68, 26) 2

8
Program Exercise
  • Open \2000SummerProject\NumberTheoryUI\2006Main.sl
    n
  • Open project Gcd
  • Add your codes into gcd.cs
  • BigInteger gcd(BigInteger x, BigInteger y)
  • //Euclidean Algorithm
Write a Comment
User Comments (0)
About PowerShow.com