ELEMENTARY NUMBER THEORY WITH PROGRAMMING ELEMENTARY NUMBER THEORY WITH PROGRAMMING MARTY LEWINTER JEANINE MEYER Copyright©2016byJohnWiley&Sons,Inc.Allrightsreserved PublishedbyJohnWiley&Sons,Inc.,Hoboken,NewJersey PublishedsimultaneouslyinCanada Nopartofthispublicationmaybereproduced,storedinaretrievalsystem,ortransmittedinany formorbyanymeans,electronic,mechanical,photocopying,recording,scanning,orotherwise, exceptaspermittedunderSection107or108ofthe1976UnitedStatesCopyrightAct,without eitherthepriorwrittenpermissionofthePublisher,orauthorizationthroughpaymentofthe appropriateper-copyfeetotheCopyrightClearanceCenter,Inc.,222RosewoodDrive,Danvers, MA01923,(978)750-8400,fax(978)750-4470,oronthewebatwww.copyright.com.Requeststo thePublisherforpermissionshouldbeaddressedtothePermissionsDepartment,JohnWiley& Sons,Inc.,111RiverStreet,Hoboken,NJ07030,(201)748-6011,fax(201)748-6008,oronlineat http://www.wiley.com/go/permissions. LimitofLiability/DisclaimerofWarranty:Whilethepublisherandauthorhaveusedtheirbest effortsinpreparingthisbook,theymakenorepresentationsorwarrantieswithrespecttothe accuracyorcompletenessofthecontentsofthisbookandspecificallydisclaimanyimplied warrantiesofmerchantabilityorfitnessforaparticularpurpose.Nowarrantymaybecreatedor extendedbysalesrepresentativesorwrittensalesmaterials.Theadviceandstrategiescontained hereinmaynotbesuitableforyoursituation.Youshouldconsultwithaprofessionalwhere appropriate.Neitherthepublishernorauthorshallbeliableforanylossofprofitoranyother commercialdamages,includingbutnotlimitedtospecial,incidental,consequential,orother damages. Forgeneralinformationonourotherproductsandservicesorfortechnicalsupport,please contactourCustomerCareDepartmentwithintheUnitedStatesat(800)762-2974,outsidethe UnitedStatesat(317)572-3993orfax(317)572-4002. Wileyalsopublishesitsbooksinavarietyofelectronicformats.Somecontentthatappearsin printmaynotbeavailableinelectronicformats.FormoreinformationaboutWileyproducts, visitourwebsiteatwww.wiley.com. LibraryofCongressCataloging-in-PublicationData: Lewinter,Marty,1950– Elementarynumbertheorywithprogramming/MartyLewinter,JeanineMeyer. pages cm Includesindex. ISBN978-1-119-06276-9(cloth) 1. Numbertheory. 2. Numbertheory–Problems,exercises,etc. 3. Computerprogramming. I. Meyer,Jeanine. II. Title. III. Title:Numbertheorywithprogramming. QA241.L58152015 512.7–dc23 2015000699 Setin11/13ptTimesbySPiGlobal,Pondicherry,India PrintedintheUnitedStatesofAmerica 10 9 8 7 6 5 4 3 2 1 The first author dedicates this book to his son and fellow mathematician, Anthony Delgado The second author dedicates this book to her mother, Esther Minkin, of blessed memory CONTENTS Preface xi Words xiii Notation in Mathematical Writing and in Programming xv 1 Special Numbers: Triangular, Oblong, Perfect, Deficient, and Abundant 1 Theprogramsincludeoneforfactoringnumbersandone totestaconjectureuptoafixedlimit. Triangular Numbers 1 Oblong Numbers and Squares 3 Deficient, Abundant, and Perfect Numbers 4 Exercises 7 2 Fibonacci Sequence, Primes, and the Pell Equation 13 Theprogramsincludeexamplesthatcountstepstocompare twodifferentapproaches. Prime Numbers and Proof by Contradiction 13 Proof by Construction 17 Sums of Two Squares 18 Building a Proof on Prior Assertions 18 Sigma Notation 19 viii CONTENTS Some Sums 19 Finding Arithmetic Functions 20 Fibonacci Numbers 22 An Infinite Product 26 The Pell Equation 26 Goldbach’s Conjecture 30 Exercises 31 3 Pascal’s Triangle 44 Theprogramsincludeexamplesthatgeneratefactorialusingiteration andusingrecursionandthusdemonstrateandcompareimportant techniquesinprogramming. Factorials 44 The Combinatorial Numbers n Choose k 46 Pascal’s Triangle 48 Binomial Coefficients 50 Exercises 50 4 Divisors and Prime Decomposition 56 TheprogramsincludeonethatusesthealgorithmtoproducetheGCD ofapairofnumbersandaprogramtoproducetheprimedecomposition ofanumber. Divisors 56 Greatest Common Divisor 58 Diophantine Equations 65 Least Common Multiple 67 Prime Decomposition 68 Semiprime Numbers 70 When Is a Number an mth Power? 71 Twin Primes 73 Fermat Primes 73 Odd Primes Are Differences of Squares 74 When Is n a Linear Combination of a and b? 75 Prime Decomposition of n! 76 No Nonconstant Polynomial with Integer Coefficients Assumes Only Prime Values 77 Exercises 78 CONTENTS ix 5 Modular Arithmetic 85 Oneprogramchecksifamodequationistrue,andanotherdetermines thesolvabilityofamodequationandthensolvesanequationthatis solvablebyabrute-forceapproach. Congruence Classes Mod k 85 Laws of Modular Arithmetic 87 Modular Equations 90 Fermat’s Little Theorem 91 Fermat’s Little Theorem 92 Multiplicative Inverses 92 Wilson’s Theorem 93 Wilson’s Theorem 95 Wilson’s Theorem (2nd Version) 95 Squares and Quadratic Residues 96 Lagrange’s Theorem 98 Lagrange’s Theorem 99 Reduced Pythagorean Triples 100 Chinese Remainder Theorem 102 Chinese Remainder Theorem 103 Exercises 104 6 Number Theoretic Functions 111 Theprogramsincludetwodistinctapproachestocalculating thetaufunction. The Tau Function 111 The Sigma Function 114 Multiplicative Functions 115 Perfect Numbers Revisited 115 Mersenne Primes 116 F(n)=Σf(d) Where d is a Divisor of n 117 The Möbius Function 119 The Riemann Zeta Function 121 Exercises 124 7 The Euler Phi Function 134 Theprogramsdemonstratetwoapproachestocalculatingthephifunction. The Phi Function 134 Euler’s Generalization of Fermat’s Little Theorem 138
Description: