Number Theory Tommy Färnqvist Seminar 12 Number Theory Outline TDDD95: APS Modular Arithmetic Seminar in Algorithmic Problem Solving April 29, 2016 Chinese Remainder Theorem Primes and Prime Testing Final Note Tommy Färnqvist Department of Computer and Information Science Linköping University 12.1 Outline Number Theory Tommy Färnqvist Outline 1 Modular Arithmetic Modular Arithmetic Chinese Remainder Theorem Primes and Prime Testing 2 Chinese Remainder Theorem Final Note 3 Primes and Prime Testing 12.2 Modular Arithmetic (Zn ) Number Theory Tommy Färnqvist Definition a ≡ b (modn) ⇔ n|(b − a), alternatively a = qn + b Outline Modular Arithmetic Chinese Remainder Theorem Zn for an integer n is an equivalence relation Primes and Prime Testing Final Note Definition (An equivalence class mod n) [a] = {x | x ≡ a (modn)} = {a + qn | q ∈ Z} • It is possible to perform arithmetic with equivalence classes mod n • This is the topic of lab 3.5 12.3 Modular Inverse Number Theory Tommy Färnqvist • What does it mean to calculate x/y mod n? • Reformulate as x · y −1 mod n • That is, we are looking for y −1 , such that y · y −1 mod n = 1 holds Recall Euclid’s algorithm for greatest common divisor: ull gcd(ull a, ull b) { ull t; while(b) t = a, a = b,b = t%b; return a; } Outline Modular Arithmetic Chinese Remainder Theorem Primes and Prime Testing Final Note And the extended Euclidean algorithm, that finds x, y such that ax + by = gcd(a, b): void exeuclid(ll a, ll b, ll *x ,ll *y) { if(!b) *x = 1, *y = 0; else exeuclid(b, a%b, y, x), *y -= *x * (a/b); } 12.4 Chinese Remainder Theorem (labs 3.6-3.7) Number Theory Tommy Färnqvist Outline Modular Arithmetic Chinese Remainder Theorem Primes and Prime Testing Final Note 12.5 Chinese Remainder Theorem (labs 3.6-3.7) Number Theory Tommy Färnqvist Outline Modular Arithmetic Chinese Remainder Theorem Primes and Prime Testing Final Note 12.6 Primes Number Theory Tommy Färnqvist Outline Modular Arithmetic Chinese Remainder Theorem Primes and Prime Testing Final Note 12.7 Prime Testing (lab 3.8) Number Theory Tommy Färnqvist Outline Modular Arithmetic Chinese Remainder Theorem Primes and Prime Testing Final Note 12.8 Prime Generation Number Theory Tommy Färnqvist Outline Modular Arithmetic Chinese Remainder Theorem Primes and Prime Testing Final Note 12.9 Prime Testing and Generation Number Theory Tommy Färnqvist Outline Modular Arithmetic Chinese Remainder Theorem Primes and Prime Testing Final Note 12.10 Next time Number Theory Tommy Färnqvist Outline Modular Arithmetic Chinese Remainder Theorem Computational Geometry. . . Primes and Prime Testing Final Note 12.11