MST Number Theory and Cryptography
Paul Yiu
Department of Mathematics Florida Atlantic University
Fall 2008 (Revised 2014)
Chapters 1-30
Contents
1 Euclidean Algorithm and Linear Diophantine Equations 101 1.1 Euclidean algorithm and gcd ...... 101 1.2 gcd(a, b) as an integer combination of a and b...... 102 1.3 Linear Diophantine equations ...... 103 1.4 Exercises ...... 103
2 Representation of integers in base b 105 2.1 Representation in a given base ...... 105 2.2 Binary expansions ...... 105 2.2.1 Calculation of high powers by repeated squaring ...... 105 2.2.2 Parity of binomial coefficients ...... 106 2.3 Highest power of a prime dividing a factorial ...... 106 2.4 Exercises ...... 107
3 Prime Numbers 109 3.1 Infinitude of prime numbers ...... 109 3.2 The sieve of Eratosthenes ...... 109 3.3 The Fundamental Theorem of Arithmetic ...... 111 3.4 The number-of-divisors function ...... 112 3.5 The sum-of-divisors function ...... 113 3.6 Perfect numbers ...... 113 3.7 Exercises ...... 114
4 Linear Congruences 115 4.1 The ring of residues modulo n ...... 115 4.2 Simultaneous linear congruences ...... 116 4.3 Exercises ...... 117
5 The Euler ϕ-function 119 5.1 Exercises ...... 120 iv CONTENTS
6 Fermat-Euler theorem 121 6.1 Primality test for Mersenne numbers ...... 121 6.2 Pseudoprimes ...... 122 6.3 Exercises ...... 122
7 Pythagorean Triangles 201 7.1 Construction of Pythagorean triangles ...... 201 7.2 Fermat Last Theorem for n =4 ...... 202 7.3 Fermat’s construction of primitive Pythagorean triangles with con- secutive legs ...... 202
8 Homogeneous quadratic equations in 3 variables 207 8.1 Pythagorean triangles revisited ...... 207 8.2 Rational points on a conic ...... 208 8.3 Integer triangles with a 60◦ angle ...... 208 8.4 Integer triangles with a 120◦ angle ...... 210
9 Heron triangles 213 9.1 The Heron formula ...... 213 9.2 Heron triangles ...... 214 9.3 Construction of Heron triangles ...... 214 9.4 Heron triangles with sides in arithmetic progression ...... 215 9.5 Heron triangles with integer inradii ...... 216
10 Genealogy of Pythagorean triangles 219 10.1 Two ternary trees of rational numbers ...... 219 10.2 Genealogy of Pythagorean triangles ...... 221
11 Polygonal numbers 225
11.1 The polygonal numbers Pk,n ...... 225 11.2 The equation Pk,a + Pk,b = Pk,c ...... 226 11.3 Double ruling of S ...... 226 11.4 Primitive Pythagorean triple associated with a k-gonal triple . . . . 227 11.5 Triples of triangular numbers ...... 228 11.6 k-gonal triples determined by a Pythagorean triple ...... 229
12 Quadratic Residues 301 12.1 Quadratic residues ...... 301 12.2 The Legendre symbol ...... 302 12.3 −1 as a quadratic residue modp ...... 303 CONTENTS v
13 The law of quadratic reciprocity 305 13.1 Gauss’ lemma ...... 305 13.2 The law of quadratic reciprocity ...... 307
14 Calculation of square roots 311 14.1 Square roots modulo p ...... 311 14.2 Square roots modulo an odd prime power ...... 313 14.3 Squares modulo 2k ...... 313
15 Primitive roots 315 15.1 Periodicity of decimal expansions of rational numbers ...... 317
16 Sums of two and four squares 319 16.1 Fermat’s two-square theorem ...... 319 16.2 Representation of integers as sums of two squares ...... 320 16.3 Lagrange’s four-square theorem ...... 320 16.3.1 Descent ...... 321
17 Finite continued fractions 401 17.1 Euler’s function F for finite continued fractions ...... 401 17.2 Cornacchia’ algorithm for a prime as a sum of two squares ....402
18 Infinite continued fractions 405
19 Lagrange’s Theorem 409 19.1 Purely periodic continued fractions ...... 409 19.2 Eventually periodic continued fractions ...... 409 19.3 Reduced quadratic irrationalities ...... 410 19.4 Proof of Lagrange’s theorem ...... 410
20 The Pell Equation 413 20.1 The equation x2 − dy2 =1 ...... 413 20.1.1 ...... 415 20.2 The equation x2 − dy2 = −1 ...... 415 20.3 The equation x2 − dy2 = c ...... 416 20.4 Applications ...... 417
21 Sums of consecutive squares 421 21.1 Sums of an odd number of consecutive squares...... 421 21.2 Even number of consecutive squares...... 423 vi CONTENTS
22 Some simple cryptosystems 501 22.1 Shift ciphers ...... 501 22.2 Affine ciphers ...... 502 22.3 A matrix encryption system ...... 505
23 A public key cryptosystem 509 23.1 RSA-cryptosystems ...... 509 23.2 Signature ...... 510
24 Factoring integers 513 24.1 Flipping a coin over the phone ...... 513 24.2 The quadratic sieve ...... 514 24.3 Factoring by continued fractions ...... 515
25 Elliptic Curves 601 25.1 Group law on y2 = x3 + ax2 + bx + c ...... 601 25.2 The discriminant ...... 602 25.3 Points of finite order ...... 604
26 Factoring Integers 2 605 26.1 Pollard’s algorithm ...... 605 26.2 Factoring with elliptic curves ...... 606
27 Some examples of the use of elliptic curves 609 27.1 The congruent number problem ...... 609 27.2 Pairs of isosceles triangle and rectangle with equal perimeters and equal areas ...... 610 27.3 Triangles with a median, an altitude, and an angle bisector concurrent611
28 Heron triangles and Elliptic Curves 613 28.1 The elliptic curve y2 =(x − k)2 − 4kx3 ...... 613 28.1.1 Proof of Theorem 28.1 ...... 616
29 The ring of Gaussian integers 701 29.1 The ring Z[i] ...... 701 29.1.1 Norm and units ...... 701 29.1.2 Gaussian primes ...... 701 29.2 An alternative proof of Fermat’s two-square theorem ...... 703
30 Construction of indecomposable Heron triangles 705 30.1 Primitive Heron triangles ...... 705 30.1.1 Triple of simplifying factors ...... 706 30.1.2 Decomposition of Heron triangles ...... 707 CONTENTS vii
30.2 Gaussian integers ...... 708 30.2.1 Heron triangles and Gaussian integers ...... 708 30.3 Orthocentric Quadrangles ...... 710 30.4 Indecomposable primitive Heron triangles ...... 711 30.4.1 Construction of Heron triangles with given simplifying factors712
Chapter 1
Euclidean Algorithm and Linear Diophantine Equations
1.1 Euclidean algorithm and gcd
The greatest common divisor (gcd) of two positive integers can be found without factorization of the integers, instead by a simple application of the Euclidean algo- rithm. Theorem 1.1 (Euclidean algorithm). Given integers a and b =0 , there are unique integers q and r satisfying a = bq + r, 0 ≤ r<|b|. (1.1) If r =0, we say that a is divisible by b, or simply that b divides a, and write b|a. Suppose a = bq + c for integers a, b, c, and q (with q nonzero). It is easy to see that every common divisor of a and b is a common divisor of b and c, and conversely. Denote by gcd(a, b) the greatest element of the (nonempty) set of common divisors of a and b. Clearly, if b|a, then gcd(a, b)=b. In general, from (1.1), we have gcd(a, b)=gcd(b, r). These observations lead to a straightforward calculation of the gcd of two numbers. To be systematic, we write a = r−1 and b = r0 (assumed positive).
r−1 =r0q0 + r1, 0 ≤ r1 r0 =r1q1 + r2, 0 ≤ r2 r1 =r2q2 + r3, 0 ≤ r3 r2 =r3q3 + r4, 0 ≤ r4 and yet remain nonnegative. In other words, some rn divides the preceding rn−1 (and leaves a remainder rn+1 =0). . . rn−2 =rn−1qn−1 + rn, 0 ≤ rn rn−1 =rnqn. From these, rn =gcd(rn−1,rn)=gcd(rn−2,rn−1)=···=gcd(r−1,r0)=gcd(a, b). 1.2 gcd(a, b) as an integer combination of a and b. The above calculation of gcd(a, b) can be retraced to give gcd(a, b) as an integer combination of a and b. Here is a more efficient way to obtain such an expression. In the table below, the integers xk and yk are obtained from qk−1 in the same way as rk, beginning with (x−1,x0)=(1, 0) and (y−1,y0)=(0, 1): xk =xk−2 − qk−1xk−1,x−1 =1,x0 =0; yk =yk−2 − qk−1yk−1,y−1 =0,y0 =1. k qk rk xk yk −1 a 1 0 0 q0 b 0 1 1 q1 r1 x1 y1 ...... n − 1 qn−1 rn−1 xn−1 yn−1 n qn rn xn yn n +1 qn+1 0 In each of these steps, rk = axk + byk. In particular, gcd(a, b)=rn = axn + byn. It can be proved that |xn| Theorem 1.2. Let p be a prime number. For every integer a not divisible by p, there exists an integer b such that ab − 1 is divisible by p. Proof. If a is not divisible by the prime number p, then gcd(a, p)=1. There are integers b and c such that ab + pc =1. It is clear that ab − 1 is divisible by p. 1.3 Linear Diophantine equations 103 1.3 Linear Diophantine equations Theorem 1.3. Let a, b, c be integers, a and b nonzero. Consider the linear Dio- phantine equation ax + by = c. (1.2) 1. The equation (1.2) is solvable in integers if and only if d := gcd(a, b) divides c. 2. If (x, y)=(x0,y0) is a particular solution of (1.2), then every integer solu- tion is of the form b a x = x + t, y = y − t, 0 d 0 d where t is an integer. 3. For c =gcd(a, b), a particular solution (x, y)=(x0,y0) of (1.2) can be found such that |x0| < |b| and |y0| < |a|. 1.4 Exercises 1. Show that (n!+1, (n +1)!+1)=1. 2. Instead of successive divisions, the gcd of two positive numbers can be found by repeated subtractions. Make use of this to find gcd(2a − 1, 2b − 1) for positive integers a and b. 3. Find a parametrization of the integer points on the line 5x +12y =3. 4. In how many ways can a number of 49-cents and 110-cents stamps were purchased with exactly 40 dollars? Is it possible to buy these with exactly 20 dollars? 5. Somebody received a check, calling for a certain amount of money in dollars and cents. When he went to cash the check, the teller made a mistake and paid him the amount which was written as cents, in dollars, and vice versa. Later, after spending $3.50, he suddenly realized that he had twice the amount of the money the check called for. What was the amount on the check? 6. Given relatively prime integers a and b, what is the largest integer which cannot be written as ax + by for nonnegative integers x and y? 104 Euclidean Algorithm and Linear Diophantine Equations Chapter 2 Representation of integers in base b 2.1 Representation in a given base Given any positive integer b>1, every positive integer n has a unique representa- tion of the form k k−1 n = ckb + ck−1b + ···+ c1b + c0 for nonnegative integers c0,c1,...,ck 2.2 Binary expansions 2.2.1 Calculation of high powers by repeated squaring Let a>1 be a fixed number, and n a large integer. The number an can be computed by repeated squaring, making use of the binary expansion of the exponent n.If n =(ckck−1 ···c1c0)2, we take successive squares k times beginning with a, and record them in the middle column in the table below. 2j j a cj 0 a 1 a2 . . . . k k a2 product 106 Representation of integers in base b n Fill the column under cj with the corresponding binary digits of n. Then a is the product of those entries (in the middle column) with a 1 in the same row and the third column. 2.2.2 Parity of binomial coefficients ··· ··· Theorem 2.1 (Lucas). Let m =(akak−1 a1a0)2 and n =(bkbk−1 b1b 0)2 be ≥ m the binary expansions of positive integers m n. The binomial coefficient n is odd if and only if for each i =0, 1,...,k, ai =1whenever bi =1. 55 = 110111 Example 2.1. 55 is odd since . 35 35 = 100011 55 = 110111 On the other hand, 55 is even since . 25 25 = 011001 2.3 Highest power of a prime dividing a factorial The exponent of the highest power of 2 dividing 18! is, counting the asterisks along the rows in the matrix below, 9+4+2+1=16. 123456789101112131415161718 ∗∗∗∗∗∗∗∗∗ ∗∗ ∗ ∗ ∗∗ ∗ Proposition 2.2. The exponent of the highest power of a prime p dividing n! is n n n + + + ··· p p2 p3 Let n =(akak−1 ···a1a0)p be the base p expansion of n. The exponent of the highest power of p dividing n! is the sum of the following numbers: ak ak−1 ak−2 ··· a2 a1 ak ak−1 ··· a3 a2 ak ··· a4 a3 ··· ··· ak ak−1 ··· ak Let R(p; k) be the integer whose base p expansion consists of k digits each of 1 k − which is 1. Clearly, R(p; k)= p−1 (p 1). Adding the numbers above along the diagonals, we have 2.4 Exercises 107 ak · R(p; k)+ak−1 · R(p; k − 1) + ···+ a2 · R(p;2)+a1 · R(p;1) pk − 1 pk−1 − 1 p2 − 1 p − 1 1 − 1 = a · + a − · + ···+ a · + a · + a · k p − 1 k 1 p − 1 2 p − 1 1 p − 1 0 p − 1 n − (a + a − + ···+ a + a ) = k k 1 1 0 . p − 1 Corollary 2.3. Let α(n) denote the number of ones in the binary expansion of n. The exponent of the highest power of 2 dividing n! is n − α(n). Theorem 2.4 (Kummer) . The exponent of the highest power of a prime p dividing a+b the binomial coefficient a is equal to the number of carries in performing the addition of a and b in base p. 2.4 Exercises 1. (a). Multiply in base 2: 11112 and 111112. (b). Let h ≥ k be positive integers. Multiply in base 2 the numbers 11 ···1 (h 1’s) and 11 ···1 (k 1’s). Distinguish between the cases h = k and h>k. 2. Solve the equation (bx −1)(by −1) = bz +1 for positive integers b>1,x,y,z. 3. Multiply in base 7: [12346]7 × [06]7 = [12346]7 × [15]7 = [12346]7 × [24]7 = [12346]7 × [33]7 = [12346]7 × [42]7 = [12346]7 × [51]7 = 4. Find all positive integers n such that 213 +210 +2n is a square. 5. Find all positive integers n such that 214 +210 +2n is a square. 6. Ask your friend to write down a polynomial f(x) with nonnegative integer coefficients. Ask her for the value of f(1). She returns 7. Ask her for the value of f(8). She returns 4305. What is the polynomial? 108 Representation of integers in base b 7. (a) What is the highest power of 2 dividing 100! ? 100 (b) What is the highest power of 2 dividing the binomial coefficient 50 ? n 8. The exponent of the highest power of 2 dividing the binomial coefficient k is α(k)+α(n − k) − α(n). 9. How many zeros are there in the end of the decimal expansion of 1000!. Answer: 249. Chapter 3 Prime Numbers 3.1 Infinitude of prime numbers A positive integer > 1 is prime if it is not divisible by any positive integer other than 1 and itself. Theorem 3.1 (Euclid). There are infinite many prime numbers. Proof. If p1,p2,...,pk were all the primes, the number p1p2 ···pk +1, not being divisible by any of them, should admit a prime factor different from any of them. This is clearly a contradiction. 3.2 The sieve of Eratosthenes √ If N is not a prime number, it must have a factor ≤ N. Given an integer N, to determine all the prime numbers ≤ N, we proceed as follows. Start with the sequence 2, 3, 4, 5, 6,...,N, with each entry unmarked, and the set P = ∅. (1) Note the√smallest entry a of the sequence that is not marked. (2) If a ≤ N, mark each entry of the sequence which is a multiple of a,but not equal to a,√ and replace P by P ∪{a}. (3) If a> N, stop. The set P now consists of the totality of prime numbers ≤ N. 110 Prime Numbers Primes below 10000 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097 1103 1109 1117 1123 1129 1151 1153 1163 1171 1181 1187 1193 1201 1213 1217 1223 1229 1231 1237 1249 1259 1277 1279 1283 1289 1291 1297 1301 1303 1307 1319 1321 1327 1361 1367 1373 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451 1453 1459 1471 1481 1483 1487 1489 1493 1499 1511 1523 1531 1543 1549 1553 1559 1567 1571 1579 1583 1597 1601 1607 1609 1613 1619 1621 1627 1637 1657 1663 1667 1669 1693 1697 1699 1709 1721 1723 1733 1741 1747 1753 1759 1777 1783 1787 1789 1801 1811 1823 1831 1847 1861 1867 1871 1873 1877 1879 1889 1901 1907 1913 1931 1933 1949 1951 1973 1979 1987 1993 1997 1999 2003 2011 2017 2027 2029 2039 2053 2063 2069 2081 2083 2087 2089 2099 2111 2113 2129 2131 2137 2141 2143 2153 2161 2179 2203 2207 2213 2221 2237 2239 2243 2251 2267 2269 2273 2281 2287 2293 2297 2309 2311 2333 2339 2341 2347 2351 2357 2371 2377 2381 2383 2389 2393 2399 2411 2417 2423 2437 2441 2447 2459 2467 2473 2477 2503 2521 2531 2539 2543 2549 2551 2557 2579 2591 2593 2609 2617 2621 2633 2647 2657 2659 2663 2671 2677 2683 2687 2689 2693 2699 2707 2711 2713 2719 2729 2731 2741 2749 2753 2767 2777 2789 2791 2797 2801 2803 2819 2833 2837 2843 2851 2857 2861 2879 2887 2897 2903 2909 2917 2927 2939 2953 2957 2963 2969 2971 2999 3001 3011 3019 3023 3037 3041 3049 3061 3067 3079 3083 3089 3109 3119 3121 3137 3163 3167 3169 3181 3187 3191 3203 3209 3217 3221 3229 3251 3253 3257 3259 3271 3299 3301 3307 3313 3319 3323 3329 3331 3343 3347 3359 3361 3371 3373 3389 3391 3407 3413 3433 3449 3457 3461 3463 3467 3469 3491 3499 3511 3517 3527 3529 3533 3539 3541 3547 3557 3559 3571 3581 3583 3593 3607 3613 3617 3623 3631 3637 3643 3659 3671 3673 3677 3691 3697 3701 3709 3719 3727 3733 3739 3761 3767 3769 3779 3793 3797 3803 3821 3823 3833 3847 3851 3853 3863 3877 3881 3889 3907 3911 3917 3919 3923 3929 3931 3943 3947 3967 3989 4001 4003 4007 4013 4019 4021 4027 4049 4051 4057 4073 4079 4091 4093 4099 4111 4127 4129 4133 4139 4153 4157 4159 4177 4201 4211 4217 4219 4229 4231 4241 4243 4253 4259 4261 4271 4273 4283 4289 4297 4327 4337 4339 4349 4357 4363 4373 4391 4397 4409 4421 4423 4441 4447 4451 4457 4463 4481 4483 4493 4507 4513 4517 4519 4523 4547 4549 4561 4567 4583 4591 4597 4603 4621 4637 4639 4643 4649 4651 4657 4663 4673 4679 4691 4703 4721 4723 4729 4733 4751 4759 4783 4787 4789 4793 4799 4801 4813 4817 4831 4861 4871 4877 4889 4903 4909 4919 4931 4933 4937 4943 4951 4957 4967 4969 4973 4987 4993 4999 5003 5009 5011 5021 5023 5039 5051 5059 5077 5081 5087 5099 5101 5107 5113 5119 5147 5153 5167 5171 5179 5189 5197 5209 5227 5231 5233 5237 5261 5273 5279 5281 5297 5303 5309 5323 5333 5347 5351 5381 5387 5393 5399 5407 5413 5417 5419 5431 5437 5441 5443 5449 5471 5477 5479 5483 5501 5503 5507 5519 5521 5527 5531 5557 5563 5569 5573 5581 5591 5623 5639 5641 5647 5651 5653 5657 5659 5669 5683 5689 5693 5701 5711 5717 5737 5741 5743 5749 5779 5783 5791 5801 5807 5813 5821 5827 5839 5843 5849 5851 5857 5861 5867 5869 5879 5881 5897 5903 5923 5927 5939 5953 5981 5987 6007 6011 6029 6037 6043 6047 6053 6067 6073 6079 6089 6091 6101 6113 6121 6131 6133 6143 6151 6163 6173 6197 6199 6203 6211 6217 6221 6229 6247 6257 6263 6269 6271 6277 6287 6299 6301 6311 6317 6323 6329 6337 6343 6353 6359 6361 6367 6373 6379 6389 6397 6421 6427 6449 6451 6469 6473 6481 6491 6521 6529 6547 6551 6553 6563 6569 6571 6577 6581 6599 6607 6619 6637 6653 6659 6661 6673 6679 6689 6691 6701 6703 6709 6719 6733 6737 6761 6763 6779 6781 6791 6793 6803 6823 6827 6829 6833 6841 6857 6863 6869 6871 6883 6899 6907 6911 6917 6947 6949 6959 6961 6967 6971 6977 6983 6991 6997 7001 7013 7019 7027 7039 7043 7057 7069 7079 7103 7109 7121 7127 7129 7151 7159 7177 7187 7193 7207 7211 7213 7219 7229 7237 7243 7247 7253 7283 7297 7307 7309 7321 7331 7333 7349 7351 7369 7393 7411 7417 7433 7451 7457 7459 7477 7481 7487 7489 7499 7507 7517 7523 7529 7537 7541 7547 7549 7559 7561 7573 7577 7583 7589 7591 7603 7607 7621 7639 7643 7649 7669 7673 7681 7687 7691 7699 7703 7717 7723 7727 7741 7753 7757 7759 7789 7793 7817 7823 7829 7841 7853 7867 7873 7877 7879 7883 7901 7907 7919 7927 7933 7937 7949 7951 7963 7993 8009 8011 8017 8039 8053 8059 8069 8081 8087 8089 8093 8101 8111 8117 8123 8147 8161 8167 8171 8179 8191 8209 8219 8221 8231 8233 8237 8243 8263 8269 8273 8287 8291 8293 8297 8311 8317 8329 8353 8363 8369 8377 8387 8389 8419 8423 8429 8431 8443 8447 8461 8467 8501 8513 8521 8527 8537 8539 8543 8563 8573 8581 8597 8599 8609 8623 8627 8629 8641 8647 8663 8669 8677 8681 8689 8693 8699 8707 8713 8719 8731 8737 8741 8747 8753 8761 8779 8783 8803 8807 8819 8821 8831 8837 8839 8849 8861 8863 8867 8887 8893 8923 8929 8933 8941 8951 8963 8969 8971 8999 9001 9007 9011 9013 9029 9041 9043 9049 9059 9067 9091 9103 9109 9127 9133 9137 9151 9157 9161 9173 9181 9187 9199 9203 9209 9221 9227 9239 9241 9257 9277 9281 9283 9293 9311 9319 9323 9337 9341 9343 9349 9371 9377 9391 9397 9403 9413 9419 9421 9431 9433 9437 9439 9461 9463 9467 9473 9479 9491 9497 9511 9521 9533 9539 9547 9551 9587 9601 9613 9619 9623 9629 9631 9643 9649 9661 9677 9679 9689 9697 9719 9721 9733 9739 9743 9749 9767 9769 9781 9787 9791 9803 9811 9817 9829 9833 9839 9851 9857 9859 9871 9883 9887 9901 9907 9923 9929 9931 9941 9949 9967 9973 3.3 The Fundamental Theorem of Arithmetic 111 3.3 The Fundamental Theorem of Arithmetic Lemma 3.2. Let p be a prime. If p|ab, then p|a or p|b. Proof. Write ab = pc for an integer c. Suppose p |a, then gcd(a, p)=1. There are integers x and y such that ax+py =1. From this, b =(ax + py)b =(ab)x + p(by)=(pc)x + p(by)=p(cx + by) is divisible by p. Theorem 3.3. Every positive integer > 1 is uniquely a product of powers of prime numbers. Proof. (Existence) This follows easily from the fact that every integer > 1 is either a prime or a product of primes. (Uniqueness) Suppose N = p1p2 ···ph, N = q1q2 ···qk, for prime numbers p1,...,ph, and q1,...,qk satisfying p1 ≤ p2 ≤···≤ph and q1 ≤ q2 ≤···≤qk. We must have h = k and pi = qi for each i =1,...,h. If this is not true, there must be a least positive integer N with two distinct factorizations as above. Note that none of the primes p1, ..., ph is equal to any of the primes q1,...,qk, for if there is a common prime p in the two lists, then N/p is a smaller positive integer with two different prime factorizations. This contradicts the minimality of N. Now we may assume p1 >q1. Consider the number N =(p1 − q1)p2 ···ph. Clearly, p1 − q1 is not divisible by q1. Therefore the prime q1 does not appear in this factorization of N . On the other hand, if we rewrite N = p1p2 ···ph − q1p2 ···ph = q1q2 ···qk − q1p2 ···ph = q1(q2 ···qk − p2 ···ph), we have a factorization containing the prime divisor q1. Hence the number N 3.4 The number-of-divisors function The number-of-divisors function: d(n):=|{d ∈ N : d|n}| . Lemma 3.4. Let a and b be relatively prime, and let ab divide ab. (a) If a is relatively prime to b, then a is a divisor of a. (b) If b is relatively prime to a, then b is a divisor of b. Proof. Suppose ab = abc for some integer c. It is enough to prove (a). If a is relatively prime to b, then there are integers x and y such that ax + by =1. From this, a = a(ax + by)=a(ax)+(ab)y = a(ax)+(abc)y = a(ax + bcy). This shows that a divides a. Corollary 3.5. Let a and b be relatively prime. Every divisor of ab is of the form ab, with a|a and b|b. Proposition 3.6. The number-of-divisors function is multiplicative, i.e., if a and b are relatively prime, then d(ab)=d(a)d(b). Proposition 3.7. Let p be a prime. d(pk)=k +1. Proof. The divisors of pk are ph for h =0,...,k. Example 3.1. Find the least number n with d(n)=12. Since 12 = 6 · 2=4· 3=3· 2 · 2, If d(n)=12, n has one of the factorizations: p11,p5q, p3q2,p2qr for prime numbers p, 1, r. The smallest is 22 · 3 · 5=60. 1 1 1 Example 3.2. In how many ways can n be written as x + y for positive integers x and y? 1 1 1 If x + y = n , we obtain, by clearing denominators, (x − n)(y − n)=n2. Therefore each factorization of n2 into a product ab with a ≤ b determines uniquely ≤ 1 1 1 1 2 x y with x + y = n . There are exactly 2 (d(n )+1)pairs. 3.5 The sum-of-divisors function 113 3.5 The sum-of-divisors function The sum-of-divisors function: σ(n):= d. d|n Proposition 3.8. The number-of-divisors function is multiplicative, i.e., if a and b are relatively prime, then σ(ab)=σ(a)σ(b). k+1 k ··· k p −1 Proposition 3.9. Let p be a prime. σ(p )=1+p + + p = p−1 . 3.6 Perfect numbers A perfect number is an integer equal to the sum of all of its divisors, including 1 but excluding the number itself. Euclid had given the following rule of construction of k−1 k 1 even perfect numbers. If Mk :=1+2+···+2 =2 − 1 is a prime number, k−1 then the number Nk := 2 Mk is perfect. Now, in terms of the function σ,an integer n is perfect if σ(n)=2n. Here is an easy proof of Euclid’s construction: k−1 k−1 k σ(Nk)=σ(2 Mk)=σ(2 )σ(Mk)=(2 − 1)(1 + Mk) k k−1 =Mk · 2 =2· 2 Mk =2Nk. Therefore, Nk is an even perfect number perfect. Euler has subsequently shown that every even perfect number must be for this form. 2 Let N be an even perfect number, factored into the form N =2k−1 · m, where k − 1 ≥ 1 and m is odd. Thus, 2N = σ(N)=σ(2k−1 · m)=σ(2k−1)σ(m)=(2k − 1)σ(m). It follows that 2N 2k m σ(m)= = · m = m + . 2k − 1 2k − 1 2k − 1 m − Note that the number 2k−1 , being the difference σ(m) m, is an integer. As such, it is a divisor of m. This expression shows that m has exactly two divisors. From m k − this we conclude that 2k−1 =1and m =2 1 is a prime. This means that every even perfect number must be of the form 2k−1(2k − 1) in which the factor 2k − 1 is a prime. This was exactly what Euclid gave. 1 k The number Mk =2 − 1 is usually known as the k-th Mersenne number. There are only 44 known Mersenne primes. The latest and greatest record is M32582657 which has 9808358 digits. It is also the greatest known prime. 2It is not known if an odd perfect number exists. 114 Prime Numbers 3.7 Exercises 1. Show that 3, 5, 7 form the only prime triple. 2. Given any integer k ≥ 2, it is always possible to find a sequence of k con- secutive integers which are all composites. 3. If n is a positive integer, does there exist a positive integer k such that the sequence k +1, 2k +1, 3k +1, ...,nk+1 consists only of composite numbers ? 4. Prove that in the infinite sequence of integers 10001, 100010001, 1000100010001,... there is no prime number. k ai 5. If n = i=1 pi is the prime factorization of n, then n has altogether τ(n)= k i=1(1 + ai) divisors. 6. Find all sequences of 49 consecutive integers whose squares add up to a square. ≥ 1 1 ··· 1 7. Prove that for n 2, 1+ 2 + 3 + + n is never an integer. √ 8. (a) Show that 2 is not a rational number. √ (b) More generally, for an integer N, N is a rational number if and only if N is the square of an integer. 9. d(n) is an odd number if and only if n is a square. 10. Find the least number n with d(n) = 100. 11. Find the least number n with d(n)=96. Chapter 4 Linear Congruences 4.1 The ring of residues modulo n Let n>1 be a positive integer. We define a relation on the set of integers: a ≡ b mod n if and only if a − b = nq for some q ∈ Z. This is an equivalence relation. For each integer x, we write [x]={y ∈ Z : y ≡ x mod n} and call this the residue class of x mod n. There are altogether n distinct residue classes, represented by 0, 1, ...,n − 1. We denote the set of residue classes by Zn. The arithmetic operations of integers respect the congruence relation modulo n, i.e.,ifa ≡ a mod n and b ≡ b mod n, then (i) a ± b ≡ a ± b mod n, (ii) ab ≡ ab mod n. Thus, there are an addition and a multiplication in the set Zn given by [a]+[b]=[a + b]and[a] · [b]=[ab]. Clearly, the additive and multiplicative identities are the residue classes [0] and [1] respectively. We summarize these by saying that Zn is a ring. A unit in Zn is an element which has a multiplicative inverse. In other words, [a] ∈ Zn is a unit if and only if there exists b such that [a][b]=[1]. This means that ab−1=nq for an integer q. From this, gcd(a, n)=1. Conversely, if gcd(a, n)=1, then there are integers b and q such that ab − nq =1, from which [a][b]=1. Theorem 4.1. (a) In Zn, a residue class [a] is a unit if and only if gcd(a, n)=1. (b) Zn is a field if and only if n is a prime number. 116 Linear Congruences Example The function f : Zm → Zn given by f([x]m)=[x]n is well defined if and only if m is divisible by n. Here [x]m denotes the residue class of x modulo m; similarly for n. 4.2 Simultaneous linear congruences An ancient Chinese problem: solve the simultaneous congruences x ≡ 2mod3,x≡ 3mod5,x≡ 2mod7. Solution. It is easier to solve the following analogous problems: (1) x ≡ 1mod3,x≡ 0mod5,x≡ 0mod7. (2) x ≡ 0mod3,x≡ 1mod5,x≡ 0mod7. (3) x ≡ 0mod3,x≡ 0mod5,x≡ 1mod7. For problem (1), we must have x ≡ 0mod35. Since 35 ≡ 2mod3, and 70 ≡ 1mod3, we may choose x1 =70for a solution of the first problem. Similarly, for problem (2), x ≡ 0mod21. Since 21 ≡ 1mod5, we may choose x2 =21for a solution of the second problem. For problem (3), x ≡ 0mod15, and we may choose x3 =15for a solution. Using these, we can find a solution to the original problem: x =2x1 +3x2 + 2x3 = 233. Since the least common multiple of 3,5,7 is 105, we may reduce this modulo 105, and obtain x ≡ 23 mod 105 for the solution. Theorem 4.2 (Chinese Remainder Theorem). Let n1,n2,...,nk be pairwise rela- tively prime integers. For arbitrary integers a1,a2,...,ak, the system of simultane- ous congruences x ≡ a1 mod n1,x≡ a2 mod n2, ..., x≡ ak mod nk, has a unique solution modulo n1n2 ···nk. Proof. For each i =1, 2,...,n, the system of simultaneous linear congruences x ≡ a1 mod n1, ...,x≡ ai mod ni, ...,x≡ ak mod nk, has a unique solution xi mod n1n2 ···ni ···nk. The original problem has solution x ≡ a1x1 + ···+ akxk mod n1n2 ···nk. 4.3 Exercises 117 4.3 Exercises 1. Solve the congruences (a) 3x ≡ 5(mod7); (b) 4x ≡ 12 (mod 16); (c) 4x ≡ 10 (mod 24). 2. Find all residues modulo 12 which have multiplicative inverses. 3. Compute 21092 mod 1093 and 21092 mod 10932. 4. Show that every nonzero element of Zn is a unit if and only if n is a prime number. 5. Solve the equation 1! + 2! + 3! + ···+ n!=m2 for positive integers m and n. 6. Counting from the right end, what is the 2500th digit of 10,000! ? 7. An army has about 20,000 soldiers. If the soldiers line up 7 by 7, there is an incomplete line of 6 soldiers; if they line up 11 by 11, there is an incomplete line of 4; if they line up 13 by 13, there is also an incomplete line of 4; if they line up 17 by 17, there is an incomplete line of 13. How many soldiers are there in the army ? 118 Linear Congruences Chapter 5 The Euler ϕ-function For a positive integer n, the Euler ϕ-function ϕ(n) gives the number of units in Zn. Z• Z This is the order of the group n of units of n. Theorem 5.1. ϕ is a multiplicative function, i.e., ϕ(mn)=ϕ(m)ϕ(n) if gcd(m, n)=1. Proof. The function F : Zmn → Zm × Zn given by F ([x]mn)=([x]m, [x]n) Z• → Z• × Z• restricts to a bijection mn m n. Lemma 5.2. Let p be a prime. (a) ϕ(p)=p − 1. k k − 1 (b) ϕ(p )=p 1 p . Proposition 5.3. 1 ϕ(n)=n 1 − . p p|n ϕ(10i + j) for 0 ≤ i, j ≤ 9 i \ j 0123456789 0 112242646 1 4104126 8 816618 2 8 12 10 22 8 20 12 18 12 28 3 8 301620162412361824 4 16 40 12 42 20 24 22 46 16 42 5 20 32 24 52 18 40 24 36 28 58 6 16 60 30 36 32 48 20 66 32 44 7 24 70 24 72 36 40 36 60 24 78 8 32 54 40 82 24 64 42 56 40 88 9 24 72 44 60 46 72 32 96 42 60 120 The Euler ϕ-function Example 5.1. We find all integers n for which ϕ(n)=24. If p is a prime divisor of n, p − 1 must be a divisor of 24 This means p must be one of 2, 3, 5, 7, 13. If n is not divisible by any of 5, 7, 13, then n =2a3b for some integers a and a b − 1 − 1 a b−1 b, and ϕ(n)=23 (1 2 )(1 3 )=23 . From this, a =3, b =2, and n =23 · 32 =72. If n is divisible by any of p =5, 7, 13, n = pm, p |m. From this, 24 = ϕ(p)ϕ(m)=(p − 1)ϕ(m). If p =5, ϕ(m)=6, m =7, 14, 18, n =35, 70, 90. If p =7, ϕ(m)=4, m =5, 8, 10, 12, n =35, 56, 70, 84. If p =13, ϕ(m)=2, m =3, 4, 6, n =39, 52, 78. Summary: ϕ(n)=24if and only if n is one of the numbers 35, 39, 45, 52, 56, 70, 72, 78, 84, 90. Example 5.2. We find all integers n for which ϕ(n) divides n. Clearly, n must be even, and every power of 2 satisfies the condition. Write n =2rk for r ≥ 1 and k>1 odd. Then ϕ(n)=2r−1ϕ(k).Ifk has l distinct prime divisors, then ϕ(k) is divisible by 2l−1 and ϕ(n) is divisible by 2k+l−1. From this, s r s−1 · p−1 we must have l =1, and k = p for an odd prime p.Now,ϕ(n)=2p 2 .If p−1 this divides n, we must have 2 dividing the prime p. This is possible only when p =3. It follows that n =2r · 3s. 5.1 Exercises 1. (a) Find all integers n for which ϕ(n) is an odd number. (b) Find all n for which ϕ(n)=2, 4, 6.