A Crash Course in Elementary Number Theory L. Felipe Martins Department of Mathematics Cleveland State University l.martins@csuohio.edu Work licensed under a Creative Commons License available at http://creativecommons.org/licenses/by-nc-sa/3.0/us/ Divisibility, Quotient and Remainder Prime Numbers and Factorization Greatest Common Divisor Modular Arithmetic February 13, 2009 The Theorems of Fermat and Euler 1 / 25 2 / 25 Divisibility a and b integers. b divides a if there is an integer q such that a qb Equivalently: b is a divisor of a b is a factor of a a is a multiple of b 23 divides 3266, because 3266 142 23 23 does not divide 2146, because 2146 93 23 7 (the remainder of 2146 by 23 is not zero). Every integer a divides 0: 0 0 a 0 does not divide any integer, with the exception of 0 itself. Quotient and remainder a and b integers, b 0. The quotient and remainder of a by b are the only integers q and r characterized by: 1. a qb r 2. br 0 and r b Divisor and remainder always have the same sign. This convention is consistent with Sage and Python. Notation: Quotient: a div b Remainder: a mod b 343 6 51 37: 343 div 51 6 and 343 mod 51 37 532 p 12q p 45q p 8q: 532 div p 45q 12 and 532 mod p 45q 8 3 / 25 4 / 25
Computing Quotient and Remainder Prime Numbers Greatest integer function: tx u denotes the largest integer that is not above x q a div b ta{bu r a mod b a qb 20 div 7 t20{7u t2.857142...u 2 and 20 mod 7 20 2 7 6 20 div p 7q t20{p 7qu t 2.857142...u 3 and 20 mod p 7q 20 p 3q p 7q 1 We say that the integer a is prime if: 1. a 1 2. The only positive divisors of a are 1 and a itself. 1 is not prime. Only positive integers can be prime, according to our definition. 2,3,5,7,11,13,...,101,...,2 43,112,609 1. If a 1 is not prime, it is said to be composite 0 and 1 are neither prime nor composite. 5 / 25 6 / 25 The Fundamental Theorem of Arithmetic Factoring by Trial Division Every positive integer can be written as product of primes, and this prime factorization is unique, except for the order of the factors. We write a prime factorization as: a p t1 1 pt2 2 ptk k k¹ The prime numbers p1, p2,...,pk are distinct and the exponents t1, t2,...,tk are positive i1 83853 3 2 7 1 11 3 11 3 7 1 3 2 11 3 3 2 7 1 2 27 1 59649589127497217 5704689200685129054721 p ti i Example: factor a 7162722 a p 527560 2 263780 2 131890 2 65945 5 13189 11 1199 11 109 109 1 527560 2 3 5 11 2 109 Can stop when the square of latest prime factor is larger than unfactored part (11 2 121 109), since every composite b has a nontrivial factor less? b 7 / 25 8 / 25
Greatest Common Divisor a and b integers, not both 0. gcdpa, bq largest integer that divides both a and b gcdpa, 0q a for a 0. (gcdp0, 0q is undefined.) Euclidean algorithm: 1. r0 a, r1 b. 2. For i 1: ri 1 ri mod ri 1. 3. Stop when rn 0. Then, gcdpa, bq rn 1. Example: gcdp2420, 1650q i ri 0 2420 1 1650 2 770 4 110 5 0 gcdp2450, 1650q 110 The Extended Euclidean Algorithm a, b, integers, not both zero 1. x0 1, y0 0, r0 a 2. x1 0, y1 1, r1 b 3. For i 1: 3.1 qi ri 1 div ri 3.2 xi 1 xi 1 qixi 3.3 yi 1 yi 1 qy yi 3.4 ri 1 ri 1 qiri 4. Stop when ri 0. (next row) (previous row) qi (current row) The ri are the same sequence of remainders of the Euclidean algorithm. All rows satisfy the relationship: axi byi ri 9 / 25 10 / 25 An Example Linear Diophantine Equations a 2420, b 1650 i xi yi ri qi 0 1 0 2420 1 0 1 1650 1 2 1 1 770 2 4 2 3 110 7 5 0 Conclusion: gcdp2420, 1650q 110 and 2420 p 2q 1650 3 110. a, b integers, not both zero. The equation ax by gcdpx, yq always has integer solutions. A solution can be found by the extended euclidean algorithm. The equation ax by c has integers solutions if and only if gcdpa, bq divides c The equation ax by 1 has integer solutions if and only if gcdpa, bq 1. In this case, a, b are said to be relatively prime or coprime. 11 / 25 12 / 25
Definition of Congruence An Example a, b are congruent modulo m if and only if m divides a b Notation: a b pmod mq a b pmod mq if and only if a and b leave the same remainder when divided by m. a 0 pmod mq if and only if m divides a. For a given modulo m, the congruence relation is an equivalence relation. Cogruence is compatible with addition and multiplication: a b pmod mq and c d pmod mq imply a c b d pmod mq and ac bd pmod mq Compute 12 2009 mod 19 Start computing: 1. 12 2 144 11 pmod 19q 2. 12 3 11 12 132 18 1 pmod 19q 3. 12 4 1 12 12 7 pmod 19q 4. 12 5 7 12 84 8 pmod 19q 5. 12 6 8 12 96 1 pmod 19q Division of 2009 by 6 gives 2009 334 6 5 12 2009 12 334 6 5 12 6 334 12 5 1 8 8 pmod 19q 13 / 25 14 / 25 Linear Congruences Solving Linear Congruences A linear congruence is an equation: ax b pmod mq ax b The linear congruence is equivalent to: pmod mq m ax b, that is, ax b my for some y which is in turn equivalent to: ax my b The linear congruence has solutions if and only if gcdpa, mq divides b. 1. Use the extended euclidean algorithm to solve: au mv g where g gcdpa, mq 2. If g gcdpa, mq b, the equation has the solution: x0 ub{g 3. A maximal set of noncongruent solutions is: tx0, x0 d, x0 2d,..., x0 pg 1qdu where d m{g. The number of noncongruent solutions is g gcdpa, mq 15 / 25 16 / 25
Example Multiplicative Inverses Modulo m 35x 10 pmod 240q a is invertible modulo m if there is a x such that: The extended euclidean algorithm gives gcdp35, 240q 5 and 35 p 41q 240 6 5 Multiplying by 10{5 2 we get one solution: x0 2 p 41q 82 158 pmod 240q The stepsize is 240{5 48, and we get the solutions: {158, 158 48, 158 2 48, 158 3 48, 158 4 48u, which reduced modulo 240 give: t158, 206, 14, 62, 110u ax 1 pmod mq, in which case x is said to be an inverse of a modulo m. a is invertible modulo m if and only if gcdpa, mq 1 If it exists, the inverse of a is unique modulo m, that is, if x1 and x2 both satify the equation above, then x1 x2 pmod mq a 1 mod m denotes the inverse x of a such that 0 x m. 17 / 25 18 / 25 Examples 1. Find the inverse (if it exists) of 65 modulo 321. Solution: The extended euclidean algorithm gives: Congruence Classes The congruence class of a modulo m is the set: 65 p 79q 321 16 1 ras tx P Z x a pmod mqu Since gcdp65, 321q 1, the inverse exists, and one inverse of 65 modulo 321 is 79. Thus: 65 1 mod 321 79 mod 321 242 2. Find the inverse (if it exists) of 214 modulo 321. Solution: The extended euclidean algorithm gives: 214 107 321 p 160q 107, and since gcdp214, 321q 107 1, 214 is not invertible modulo 321. if m 6: r0s t..., 12, 6, 0, 6, 12,...u r1s t..., 11, 5, 1, 7, 13,...u r4s t..., 18, 2, 4, 10, 16,...u r10s r4s because 10 4 pmod 6q Any element b in ras is said to be a representative of the congruence class ras, and rbs ras. The set of congruence classes modulo m is: Z{mZ tr0s, r1s,..., rm 1su 19 / 25 20 / 25
Operations in Z{mZ Fermat s Theorem ras rbs ra bs and rasrbs rabs Definition is consistent, that is, it does not depend on the representatives chosen for the congruence classes. in Z{6Z, we have: r2s r3s r5s, r2sr3s r6s r0s, r5sr5s r25s r1s, r35sr1000s r 1sr4s r 4s r2s pz{mz,, q is a commutative ring: Addition and multiplication are defined, and have the usual properties : commutative, associative, is distributive with respect to, 1 is the identity of multiplication, etc. Elements are not required to have a multiplicative inverse: ras is invertible if and only if gcdpa, mq 1, and then ras 1 ra 1 mod ms. From now on, the modulus is a prime number p. Every a that is not a multiple of p is invertible modulo p Cancellation law: if ab ac and a is not a multiple of p, then b c pmod pq If p a, the two lists of integers: 1, 2,..., p 1 and 1a, 2a, pp 1qa consist of the same integers, modulo p Thus: 1 2 pp 1q 1a 2a pp 1qa pmod pq and, rearranging terms: 1 2 pp 1q 1 2 pp 1q a p 1 pmod pq. Using cancellation again: a p 1 1 pmod pq. Example 21 / 25 Euler s φ function 22 / 25 Compute 12 2009 mod 19. 19 is prime and 12 is not a multiple of 19. Fermat s theorem gives: 12 18 1 pmod 19q Using division: 2009 111 18 11 12 2009 12 111 18 11 12 18 111 12 11 12 11 pmod 19q Computing 12 11 pmod 19q: 12 2 144 11 pmod 19q 12 4 11 2 121 7 pmod 19q 12 8 7 2 49 11 pmod 19q 12 11 12 8 2 1 11 11 12 7 12 84 8 pmod 19q φpaq number of integers in t1, 2,..., au that are relatively prime to a If the prime factorization of a is p t1 1 pt2 2 ptk k, then: φpaq p t1 1 1 pp1 1qp t2 1 tk 1 2 pp2 1q pk ppk 1q a 1 1 1 1 1 1 p1 p2 pk Example: Compute φp44982q. 44982 2 3 3 7 2 17 φp44982q 2 0 p2 1q 3 2 p3 1q 7 1 p7 1q 17 0 p17 1q 12096 23 / 25 24 / 25
Euler s Theorem Let a and m be integers. If gcdpa, mq 1, then: a φpmq 1 pmod mq Example: compute 13 1233797 mod 44982 φp44982q 12096 and gcdp13, 44982q 1. so, by Euler s thoerem: 13 12096 1 pmod 44982q 1233797 102 12096 5 13 1233797 13 102 12096 5 13 5 11437 pmod 44982q 25 / 25