Lecture 7: Number Theory Steven Skiena. skiena

Similar documents
Lecture 7 Number Theory Euiseong Seo

3 The fundamentals: Algorithms, the integers, and matrices

4 Number Theory and Cryptography

a the relation arb is defined if and only if = 2 k, k

The set of integers will be denoted by Z = {, -3, -2, -1, 0, 1, 2, 3, 4, }

The Euclidean Algorithm and Multiplicative Inverses

Outline. Number Theory and Modular Arithmetic. p-1. Definition: Modular equivalence a b [mod n] (a mod n) = (b mod n) n (a-b)

Solution Sheet (i) q = 5, r = 15 (ii) q = 58, r = 15 (iii) q = 3, r = 7 (iv) q = 6, r = (i) gcd (97, 157) = 1 = ,

Q 2.0.2: If it s 5:30pm now, what time will it be in 4753 hours? Q 2.0.3: Today is Wednesday. What day of the week will it be in one year from today?

Math 131 notes. Jason Riedy. 6 October, Linear Diophantine equations : Likely delayed 6

Chapter 3 Basic Number Theory

CPSC 467b: Cryptography and Computer Security

Number Theory. Zachary Friggstad. Programming Club Meeting

Basic elements of number theory

Basic elements of number theory

2x 1 7. A linear congruence in modular arithmetic is an equation of the form. Why is the solution a set of integers rather than a unique integer?

1 Overview and revision

cse 311: foundations of computing Fall 2015 Lecture 12: Primes, GCD, applications

Numbers. Çetin Kaya Koç Winter / 18

cse 311: foundations of computing Spring 2015 Lecture 12: Primes, GCD, applications

2x 1 7. A linear congruence in modular arithmetic is an equation of the form. Why is the solution a set of integers rather than a unique integer?

Applied Cryptography and Computer Security CSE 664 Spring 2017

Maths Probability Problems. Maths. League of Programmers. ACA, IIT Kanpur. October 22, 2012

ELEMENTS OF NUMBER THEORY

This is a recursive algorithm. The procedure is guaranteed to terminate, since the second argument decreases each time.

CHAPTER 3. Congruences. Congruence: definitions and properties

CPSC 467: Cryptography and Computer Security

Intermediate Math Circles February 26, 2014 Diophantine Equations I

8 Primes and Modular Arithmetic

Congruence Classes. Number Theory Essentials. Modular Arithmetic Systems

Lecture 11 - Basic Number Theory.

Ch 4.2 Divisibility Properties

Addition. Ch1 - Algorithms with numbers. Multiplication. al-khwārizmī. al-khwārizmī. Division 53+35=88. Cost? (n number of bits) 13x11=143. Cost?

Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry. Spring 2006

CMPUT 403: Number Theory

3.7 Non-linear Diophantine Equations

2 Elementary number theory

Number Theory Proof Portfolio

Number Theory and Group Theoryfor Public-Key Cryptography

Introduction to Information Security

Integers and Division

7. Prime Numbers Part VI of PJE

Discrete Mathematics GCD, LCM, RSA Algorithm

Topics in Cryptography. Lecture 5: Basic Number Theory

Number Theory Notes Spring 2011

For your quiz in recitation this week, refer to these exercise generators:

Number Theory. CSS322: Security and Cryptography. Sirindhorn International Institute of Technology Thammasat University CSS322. Number Theory.

Discrete Structures Lecture Primes and Greatest Common Divisor

MATH 501 Discrete Mathematics. Lecture 6: Number theory. German University Cairo, Department of Media Engineering and Technology.

Senior Math Circles Cryptography and Number Theory Week 2

Elementary Number Theory. Franz Luef

Lecture notes: Algorithms for integers, polynomials (Thorsten Theobald)

Elementary Number Theory MARUCO. Summer, 2018

CS 5319 Advanced Discrete Structure. Lecture 9: Introduction to Number Theory II

Number theory (Chapter 4)

Chapter 2. Divisibility. 2.1 Common Divisors

ECEN 5022 Cryptography

MTH 346: The Chinese Remainder Theorem

CS483 Design and Analysis of Algorithms

Outline. Some Review: Divisors. Common Divisors. Primes and Factors. b divides a (or b is a divisor of a) if a = mb for some m

Outline. AIT 682: Network and Systems Security. GCD and Euclid s Algorithm Modulo Arithmetic Modular Exponentiation Discrete Logarithms

[Part 2] Asymmetric-Key Encipherment. Chapter 9. Mathematics of Cryptography. Objectives. Contents. Objectives

PUTNAM TRAINING NUMBER THEORY. Exercises 1. Show that the sum of two consecutive primes is never twice a prime.

2 Arithmetic. 2.1 Greatest common divisors. This chapter is about properties of the integers Z = {..., 2, 1, 0, 1, 2,...}.

Math From Scratch Lesson 20: The Chinese Remainder Theorem

Chapter 4 Finite Fields

Lecture 4: Number theory

MATH 145 Algebra, Solutions to Assignment 4

An integer p is prime if p > 1 and p has exactly two positive divisors, 1 and p.

Number Theory. Modular Arithmetic

CSC 474 Network Security. Outline. GCD and Euclid s Algorithm. GCD and Euclid s Algorithm Modulo Arithmetic Modular Exponentiation Discrete Logarithms

Some Facts from Number Theory

Lecture Notes. Advanced Discrete Structures COT S

Math 110 FOUNDATIONS OF THE REAL NUMBER SYSTEM FOR ELEMENTARY AND MIDDLE SCHOOL TEACHERS

4 Powers of an Element; Cyclic Groups

Discrete Mathematics and Probability Theory Fall 2018 Alistair Sinclair and Yun Song Note 6

22. The Quadratic Sieve and Elliptic Curves. 22.a The Quadratic Sieve

Introduction to Cryptography. Lecture 6

Lecture 2. The Euclidean Algorithm and Numbers in Other Bases

With Question/Answer Animations. Chapter 4

11 Division Mod n, Linear Integer Equations, Random Numbers, The Fundamental Theorem of Arithmetic

ALGEBRA+NUMBER THEORY +COMBINATORICS

Chapter 1 A Survey of Divisibility 14

CHAPTER 6. Prime Numbers. Definition and Fundamental Results

18 Divisibility. and 0 r < d. Lemma Let n,d Z with d 0. If n = qd+r = q d+r with 0 r,r < d, then q = q and r = r.

All variables a, b, n, etc are integers unless otherwise stated. Each part of a problem is worth 5 points.

CSC 474 Information Systems Security

Elementary Number Theory Review. Franz Luef

CISC-102 Fall 2017 Week 6

Mathematical Foundations of Cryptography

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 3

The next sequence of lectures in on the topic of Arithmetic Algorithms. We shall build up to an understanding of the RSA public-key cryptosystem.

Lecture 3.1: Public Key Cryptography I

M381 Number Theory 2004 Page 1

7.2 Applications of Euler s and Fermat s Theorem.

An Introduction to Mathematical Thinking: Algebra and Number Systems. William J. Gilbert and Scott A. Vanstone, Prentice Hall, 2005

Arithmetic and Algebra

cse547, math547 DISCRETE MATHEMATICS Professor Anita Wasilewska

Chapter 9 Basic Number Theory for Public Key Cryptography. WANG YANG

Transcription:

Lecture 7: Number Theory Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.sunysb.edu/ skiena

Number Theory and Divisibility G-d created the integers. All else is the work of man. Kronecker. Number theory is the study of the properties of the integers, specifically integer divisibility. It is a fascinating area is beautiful proofs and surprising results. We say b divides a (denoted b a) if a = bk for some integer k. Equivalently, we say that b is a divisor of a or a is a multiple of b if b a. As a consequence of this definition, the smallest natural divisor of every non-zero integer is 1. In general there is no integer k such that a = 0 k.

Prime Numbers A prime number is an integer p > 1 which is only divisible by 1 and itself. Said another way, if p is a prime number, then p = a b for integers a b implies that a = 1 and b = p. The fundamental theorem of arithmetic. states is that every integer can be expressed in only one way as the product of primes. 105 is uniquely expressed as 3 5 7, and 32 is uniquely expressed as 2 2 2 2 2. This unique set of numbers multiplying to n is called the prime factorization of n. Any number which is not prime is said to be composite.

Primality Testing and Factorization Not only are there an infinite number of primes (see Euclid s proof), but there are a lot of them. There are roughly x/ lnx primes less than or equal to x, i.e. roughly one out of every ln x numbers is prime. The easiest way to find the prime factorization of an integer n is repeated division. Note the that smallest prime factor is must at most n unless n is prime.

Constructing all Divisors Every divisor is the product of some subset of these prime factors. Such subsets can be constructed using backtracking techniques, but we must be careful about duplicate prime factors. For example, the prime factorization of 12 has three terms (2, 2, and 3) but 12 has only 6 divisors (1, 2, 3, 4, 6, 12).

Greatest Common Divisor The greatest common divisor, or gcd, the largest divisor shared by a given pair of integers. The reduced form of the fraction 24/36 comes after we divide both the numerator and denominator by gcd(x,y), in this case 12. Euclid s GCD algorithm rests on two observations. First, If b a, then gcd(a,b) = b. This should be pretty clear. If b divides a, then a = bk for some integer k, and thus gcd(bk,b) = b. Second, If a = bt + r for integers t and r, then gcd(a,b) = gcd(b,r).

Why? By definition, gcd(a,b) = gcd(bt +r, b). Any common divisor of a and b must rest totally with r, because bt clearly must be divisible by any divisor of b. It can also find integers x and y such that a x + b y = gcd(a,b) which will prove quite useful in solving linear congruences.

Implementation /* Find the gcd(p,q) and x,y such that p*x + q*y = gcd(p,q) */ long gcd(long p, long q, long *x, long *y) { long x1,y1; /* previous coefficients */ long g; /* value of gcd(p,q) */ if (q > p) return(gcd(q,p,y,x)); if (q == 0) { *x = 1; *y = 0; return(p); } g = gcd(q, p%q, &x1, &y1); *x = y1; *y = (x1 - floor(p/q)*y1); } return(g); The least common multiple (lcm), the smallest integer which is divided by both of a given pair of integers. For example, the least common multiple of 24 and 36 is 72. To compute it, observe that lcm(x,y) = xy/gcd(x,y).

Modular Arithmetic Sometimes computing the remainder is more important than a quotient. What day of the week will your birthday fall on next year? All you need to know is the remainder of the number of days between now and then (either 365 or 366) when dividing by the 7 days of the week. Thus it will fall on this year s day plus one (365mod7) or two (366mod7) days, depending upon whether it is affected by a leap year. The key to such efficient computations is modular arithmetic. The number we are dividing by is called the modulus, and the remainder left over is called the residue.

What is (x + y)modn? We can simplify this to ((xmodn) + (ymodn))modn to avoid adding big numbers. Subtraction s just a special case of addition. (12mod100) (53mod100) = 41mod100 = 59mod100 Notice how we can convert a negative number mod n to a positive number by adding a multiple of n to it.

Exponentiation Since multiplication is just repeated addition, xymod n = (xmod n)(ymod n)mod n Since exponentiation is just repeated multiplication, x y modn = (xmodn) y modn Since exponentiation is the quickest way to produce really large integers, this is where modular arithmetic really proves its worth. Division proves considerably more complicated to deal with...

What is the Last Digit? What is the last digit of 2 100? We can do this computation by hand. What we really want to know is what 2 100 mod10 is. By doing repeated squaring, and taking the remainder mod10 at each step we make progress very quickly: 2 3 mod10 = 8 2 6 mod10 = 8 8mod10 4 2 12 mod10 = 4 4mod10 6 2 24 mod10 = 6 6mod10 6 2 48 mod10 = 6 6mod10 6 2 96 mod10 = 6 6mod10 6 2 100 mod10 = 2 96 2 3 2 1 mod10 6

Congruences Congruences are an alternate notation for representing modular arithmetic. We say that a b(modm) if m (a b). By definition, if amodm is b, then a b(mod m). It gets us thinking about the set of integers with a given remainder n, and gives us equations for representing them. What integers x satisfy the congruence x 3(mod 9)? The set of solutions is all integers of the form 9y + 3, where y is any integer. What about 2x 3(mod 9) and 2x 3(mod 4)? Trial and error should convince you that exactly the integers of the form 9y + 6 satisfy the first example, while the second has no solutions at all.

Operations on Congruences Congruences support addition, subtraction, and multiplication, as well as a limited form of division provided they share the same modulus: Addition and Subtraction Suppose a b(mod n) and c d(mod n). Then a + c b + d(mod n). If 4x 7(mod 9) and 3x 3(mod 9), then 4x 3x 7 3(mod 9) x 4(mod 9) Multiplication General multiplication holds, i.e., a b(mod n) and c d(mod n) implies ac bd(mod n).

Division We cannot cavalierly cancel common factors from congruences. Note that 6 2 6 1(mod 3), but clearly 2 1(mod 3). Note that division can be defined as multiplication by an inverse, so a/b is equivalent to ab 1. But this inverse does not always exist try to find a solution to 2x 1(mod 4).

Simplifying and Solving Congruences We can simplify a congruence ad bd(mod dn) to a b(mod n), so we can divide all three terms by a mutually common factor if one exists. Thus 170 30(mod 140) implies that 17 3(mod 14). A linear congruence is an equation of the form ax b(mod n). Solving this equation means identifying which values of x satisfy it. Not all such equations have solutions. ax 1(mod n) has a solution if and only if the modulus and the multiplier are relatively prime, i.e., gcd(a, n) = 1. We may use Euclid s algorithm to find this inverse through the solution to a x + n y = gcd(a,n) = 1.

In general, there are three cases, depending on the relationship between a, b, and n: gcd(a,b,n) > 1 Then we can divide all three terms by this divisor to get an equivalent congruence. This gives us a single solution mod the new base, or equivalently gcd(a, b, n) solutions (mod n). gcd(a,n) does not divide b The congruence can have no solution. gcd(a,n) = 1 Then there is one solution (mod n). Further, x = a 1 b works, since aa 1 b b(mod n). This inverse exists and can be found using Euclid s algorithm.

More Advanced Tools The Chinese remainder theorem gives us a tool for working with systems of congruences over different moduli. Suppose there is exists an integer x such that x a 1 (mod m 1 ) and x a 2 (mod m 2 ). Then x is uniquely determined (mod m 1 m 2 ) if m 1 and m 2 are relatively prime.

Diophantine Equations Diophantine equations are formulae in which the variables are restricted to integers. For example, Fermat s last theorem concerned answers to the equation a n + b n = c n. The most important class are linear Diophantine equations of the form ax ny = b, where x and y are the integer variables and a, b, and n are integer constants. These are readily shown to be equivalent to the solving the congruence ax b(mod n) and hence can be solved using the techniques above.

110702 (Carmichael Numbers) Which composite integers n always satisfy the equation a n modn = a Does this require large integer arithmetic?

110704 (Factovisors) Does a divide n!? Does this require large integer arithmetic?

110707 (Marbles) What is the cheapest way to perfectly store n among two types of boxes?

110708 (Repackaging) Cups of three sizes are sold in certain predefined sets with a given number of each type of cup per package. Can we buy packages so we end up with exactly the same number of all three types of cups?