INDEX

Note: Page in italics refer to Figures; those in bold to Tables. abundant numbers, 4–7 congruence classes mod k , 7 congruent mod k, 86 arithmetic functions, 20–22 consecutive numbers, sequence, 85 associative array, 185–6 incongruent mod k, 86 least residues, 86–7 binary complement, 187 modular arithmetic, 86 binary numbers, 166, 187, 194 congruent mod k, 86 Binet’s formula, 25 cryptography binomial coefficients, 50 ciphertext, 183 binomial theorem, 28 factoring large numbers, 188–91 brute-force approach, 30 history, 182–7 knapsack problem, 191–2 Chinese remainder theorem, 102–4 modular equation, 183 ciphertext, 183, 185 plaintext, 183, 184 combinatorial numbers,COPYRIGHTED 46–8, 50 public-key, MATERIAL 187–8 complements, 47, 187 science of encoding complex analysis, 159 information, 182–3 composite , 5, 13–14, 17, 63, substitution code, 183, 185 75, 148, 168 superincreasing sequences, 192–4 computational complexity, 191 two-digit , 184, 185

Elementary with Programming, First Edition. Marty Lewinter and Jeanine Meyer. © 2016 John Wiley & Sons, Inc. Published 2016 by John Wiley & Sons, Inc. 208 INDEX decryption exponent, 188 for-loop, 14–15, 19, 30, 49, deficient numbers, 4–7 135, 186 Diophantine equations, 65–7, 90, 159–60 Gaussian , 167, 174 distinct binary partition, 164–5, 187 Goldbach’s conjecture, 30 divergent series, 121, 167 golden ratio, 23 greatest common , 58–64 hard-coding, 2 laws of divisibility, 57–8 harmonic series, 122 multiplicative function, 117–19 html elements, 1–2, 15, 30, 69 prime divisor, 13, 123, 139 proper, 56, 116 incongruent mod k, 86 sigma function, 114–15 infinite product, 26, 122, 163, 165 tau function, 111–14 isaSquare, 189 “dot matrix” representation, 161, 161 isEven function, 189 double precision, 46 isPrime, 69 dummy variable, 19 iterative way, 44 encryption exponent, 187 JavaScript, 4–5, 15, 28, 30, 90, 112 Euler phi function array methods, unshift and push Fermat’s little theorem, 138 adds, 49 index of m (mod p), 141–5 binary representation, 166 Legendre symbol, 146–7 built-in sort method, 186 order of a (mod n), 139–40 double precision, 46 phi function, 134–8 push, 16 primitive roots, 140–141 product of m and n, 139 knapsack problem, 191–2, 194 quadratic reciprocity, 147 kth order differences, 21 quadratic residue, 145–6 x2 = a (mod n), solution, 148–50 Lagrange’s theorem, 98–100 Euler’s theorem, 139, 188 least common multiple (lcm), 67–8 least residues, 86–7, 92–3, 96–7 factorials, 44–6 Legendre symbol, 146–7 factoring large numbers, 188–91 lemmas, 100 Fermat primes, 73–4 lettercount, 186–7 Fermat’s little theorem, 91–2, linear combination, 57–8, 138, 142 62, 75–6 Fibonacci numbers, 64 Binet’s formula, 25 Mersenne primes, 6, 116–17 golden ratio, 23 meta tag, 2 ordered partitions, 23–4 Möbius function, 119–21 recursive relation, 23, 25 Möbius inversion formula, 120, 137 first differences, 20–21 modular arithmetic flag variable, 15 Chinese remainder theorem, floating point, 28, 46, 136 102–4 INDEX 209

congruence classes mod k, 85–7 infinite product, 163 definition, 86 nth power, 160–167 Fermat’s little theorem, 91–2 odd and distinct, 163–4 Lagrange’s theorem, 98–100 ordered, 23–4, 161–2 laws, 87–9 summands, 161–2 modular equations, 90–91 transpose of matrix, 161, 161 multiplicative inverses, 92–3 Pascal’s triangle reduced Pythagorean triples, binomial coefficients, 50 100–102 combinatorial numbers, 46–8, 50 squares and quadratic factorials, 44–6 residues, 96–8 Pell equation, 26–9, 102 Wilson’s theorem, 93–6 perfect numbers, 4–7, 115–16 modular equations, 90–91 phi function, 134–8 see also Euler phi modulo operation, 4, 15 function mth power numbers, 71–2 plaintext, 183, 185, 187 multiplicative functions, 115, 118 precision, 28, 46 multiplicative inverses, 92–3, 138, prime decomposition, 76–7 183, 193 definition, 68 positive integer, 68–70 NP-complete, 191 tau function, 112–13 NP-hard, 191 primeDecomposition.js, 112 number theoretic functions prime numbers F(n) = Σf(d), 117–19 , 13–14 Mersenne primes, 116–17 definition, 5 Möbius function, 119–21 proof by construction, 17–18 multiplicative functions, 115 proof by contradiction, 13–17 perfect numbers revisited, 115–16 sums of two squares, 18 Riemann zeta function, 121–4 primes array, 16–17, 30 sigma function, 114–15 prime values, 77–8 tau function, 111–14 primitive recursion, 45 primitive roots, 140–145 oblong numbers, 3–4, 20 pseudocode, 45 odd numbers public-key cryptography classify function, 6 decryption exponent, 188 consecutive, 18–19 encryption exponent, 187 row sums of triangular array, 160 RSA system, 188 odd primes, 74–5 push (), 16 ordered partitions, 23–4, 161–3 Pythagorean theorem, 100 Pythagorean triples, 100–102, 158–9 pairwise relatively prime, 103 palindromes, 96 quadratic nonresidue, 145–6 partitions quadratic reciprocity, 147 binary numbers, 166 law of, 148 distinct binary, 164–5 quadratic residues “dot matrix” representation, 161, 161 Legendre symbol, 146–7 210 INDEX quadratic residues (cont’d) odd primes, 74–5 quadratic nonresidue, 145 of primes, 57 and squares, 96–8 quadratic residues, 96–8 x2 = a (mod n), solution, 148–50 sums of four or fewer squares, 170–174 recursion, 45–6, 61 sums of two squares, 18, recursive relation, 23–5, 27, 64 158–9, 167–70 reduced Pythagorean triple (RPT), substitution code, 183, 185 100–102 sums Riemann zeta function Diophantine equation, 159–60 divergent series, 121–2 of four or fewer squares, harmonic series, 122 170–174 infinite product, 122 nth power, 158–9 prime divisors, 123–4 odd numbers, 160 Rivest, Shamir, and Adleman (RSA) of two squares, 167–70 system, 188 superincreasing sequences, 192–4 RPT see reduced Pythagorean triple (RPT) tauFF, 112–13 RSA system see Rivest, Shamir, and tau function Adleman (RSA) system definition, 111 divisors, 113–14 script element, 2, 112, 136 prime decomposition, 112–13 second differences, 21–2 third differences, 21 numbers, 70–71, 187 toString (), 166 shift method, 69 triangular numbers, 1–3 sigma function, 114–15 twin primes, 73 sigma notation, 19 source code, 15 variable, 2, 5–6, 15–17, 19, 49, 62, square-free number, 119–20, 123, 69–70, 91, 135, 186, 190 137, 169 squares while loop, 49, 167 oblong numbers, 3–4 Wilson’s theorem, 93–6