This action might not be possible to undo. Are you sure you want to continue?

Jaehyun Park

Today’s Lecture

Algebra Number Theory Combinatorics (non-computational) Geometry Emphasis on “how to compute”

Sum of Powers 𝑛 2 𝑘 𝑘=1 = 1 𝑛(𝑛 6 + 1)(2𝑛 + 1) 1 𝑛 2 𝑘 = 3 𝑘 2 = 𝑛 + 1 2 Pretty useful in many random situations Memorize above! .

if 𝑛 is odd 2 (𝑛−1)/2 𝑎 Can be computed recursively . if 𝑛 = 0 𝑎 . if 𝑛 is even ∙ 𝑎. if 𝑛 = 1 2 𝑛/2 𝑎 .Fast Exponentiation 𝑎𝑛 = 1.

double t = pow(a. } Running time: 𝑂 log 𝑛 . if(n == 1) return a.Implementation (recursive) double pow(double a. int n) { if(n == 0) return 1. n/2). return t * t * pow(a. n%2).

n /= 2.Implementation (non-recursive) double pow(double a. int n) { double ret = 1. } You should understand how it works . } return ret. while(n) { if(n%2 == 1) ret *= a. a *= a.

Linear Algebra Gaussian Elimination Solve a system of linear equations Invert a matrix Find the rank of a matrix Compute the determinant of a matrix Cramer’s Rule .

0 = 𝑎 gcd (𝑎. 𝑏 = gcd (𝑎. 𝑏): greatest integer divides both 𝑎 and 𝑏 Used very frequently in number theoretical problems Some facts: gcd 𝑎. 𝑏) is the smallest positive number in {𝑎𝑥 + 𝑏𝑦|𝑥. 𝑏 − 𝑎) gcd 𝑎. 𝑦 ∈ 𝑍} .Greatest Common Divisor (GCD) gcd (𝑎.

𝑏 = gcd (𝑎. 867 = gcd 255. 102 = gcd 51. 0 = 51 . 867 = gcd 255.Euclidean Algorithm Repeated use of gcd 𝑎. 102 = gcd 51. 867 = gcd 1989 − 2 × 867. 𝑏 − 𝑎) gcd 1989. 102 − 2 × 51 = gcd 51. 102 = gcd 255 − 2 × 102. 867 − 3 × 255 = gcd 255.

} Running time: 𝑂 log 𝑎 + 𝑏 Be careful: a % b follows the sign of a 5 % 3 == 2 -5 % 3 == -2 . int b) { while(b){int r = a % b. b = r. a = b.} return a.Implementation int gcd(int a.

Inverse of 2 mod 4) Exists iff gcd 𝑥.Congruence & Modulo Operation 𝑥 ≡ 𝑦(mod𝑛) means 𝑥 and 𝑦 have the same remainder when divided by 𝑛 Multiplicative inverse is the inverse of 𝑥 modulo 𝑛 if 𝑥𝑥 −1 ≡ 1(mod𝑛) −1 5 ≡ 3(mod7) because 5 ⋅ 3 ≡ 15 ≡ 1(mod7) May not exist (e.g. 𝑛 = 1 𝑥 −1 .

then 𝑎𝑥 + 𝑛𝑦 = 1 for some 𝑥 . 𝑏 = 𝑎𝑥 + 𝑏𝑦 for some integers 𝑥 . 𝑛 = 1. We will be done if we can find such 𝑥 and 𝑦 . 𝑦 Taking modulo 𝑛 gives 𝑎𝑥 ≡ 1(mod𝑛) Therefore.Multiplicative Inverse All intermediate numbers computed by Euclidean algorithm are integer combinations of 𝑎 and 𝑏 gcd 𝑎. 𝑦 If gcd 𝑎.

but write all intermediate numbers as integer combinations of 𝑎 and 𝑏 Exercise: implementation! .Extended Euclidean Algorithm Main idea: keep the original algorithm.

𝑏.Chinese Remainder Theorem Given 𝑎. 𝑚 such that 𝑛 and 𝑚 are coprime Find 𝑥 such that 𝑥 ≡ 𝑎 mod𝑚 . 𝑥 ≡ 𝑏 mod𝑛 Solution: 𝑛−1 be the inverse of 𝑛 modulo 𝑚 −1 be the inverse of 𝑚 modulo 𝑛 Let 𝑚 −1 + 𝑏𝑚𝑚−1 (check this yourself) Set 𝑥 = 𝑎𝑛𝑛 Let Extension: solving for more simultaneous equations . 𝑛.

𝑛 𝑘 the coefficient of 𝑥 𝑘 𝑦 𝑛−𝑘 in the expansion of 𝑥 + 𝑦 𝑛 Appears everywhere in combinatorics .Binomial Coefficients is the number of ways to choose 𝑘 objects out of 𝑛 distinguishable objects or.

but 𝑘 or 𝑛 − 𝑘 is small Use Solution 1 (carefully) .Computing 𝑛 𝑘 Solution 1: Compute using the following formula 𝑛 𝑛(𝑛 − 1) ⋯ (𝑛 − 𝑘 + 1) = 𝑘 𝑘! Solution 2: Use Pascal’s triangle Case 1: Both 𝑛 and 𝑘 are small Use either solution Case 2: 𝑛 is big.

𝐹1 = 1 𝐹 𝑛 = 𝐹𝑛−1 + 𝐹𝑛−2 .Fibonacci sequence Definition: 𝐹0 = 0. where 𝑛 ≥ 2 Appears in many different contexts .

where 𝜑 = 1+ 5 2 Bad because 𝜑 and 5 are irrational Cannot compute the exact value of 𝐹𝑛 for large 𝑛 There is a more stable way to compute 𝐹𝑛 … and any other recurrence of a similar form .Closed Form 𝐹𝑛 = 𝜑𝑛 −𝜑 5 𝑛 .

Better Closed Form 𝐹𝑛+1 1 1 𝐹𝑛 1 1 = = 𝐹𝑛 1 0 𝐹𝑛−1 1 0 𝑛 𝐹1 𝐹0 Use fast exponentiation to compute the matrix power Can be extended to support any linear recurrence with constant coefficients .

Geometry In theory: not that hard In programming contests: avoid if you can… Will cover basic stuff today Computational geometry in week 9 .

don’t use floating-point numbers If you have to. always use double and never use float Avoid division whenever possible Introduce small constant 𝜖 in (in)equality tests e. precision. write if(abs(x) < EPS) No hacks! In most cases. Instead of if(x == 0).When Solving Geometry Problems Precision. small perturbations won’t help .g. randomization. precision! If possible. probabilistic methods.

−𝑦. 𝑥 Memorize all of them! . 𝑦) Norm (distance from the origin): 𝑥 2 + 𝑦 2 Counterclockwise rotation by 𝜃 : cos 𝜃 − sin 𝜃 Left-multiply by sin 𝜃 cos 𝜃 Make sure to use correct units (degrees. radians) Normal vectors: (𝑦. −𝑥).2D Vector Operations Have a vector (𝑥.

Line-Line Intersection Have two lines: 𝑎𝑥 + 𝑏𝑦 + 𝑐 = 0. 𝑑𝑥 + 𝑒𝑦 + 𝑓 = 0 Write in matrix form: 𝑎 𝑑 𝑐 𝑏 𝑥 = − 𝑓 𝑦 𝑒 Invert the matrix on the left using the following: 1 𝑎 𝑏 −1 𝑒 = 𝑎𝑒−𝑏𝑑 −𝑑 𝑑 𝑒 Memorize this! −𝑏 𝑎 Edge case: 𝑎𝑒 = 𝑏𝑑 .

𝐵. 𝐶 Want to compute 𝑃 that is equidistance from 𝐴.Circumcircle of a Triangle Have three points 𝐴. 𝐶 Don’t try to solve the system of quadratic equations! Instead. 𝐵. do the following: the bisectors of 𝐴𝐵 and 𝐵𝐶 Compute their intersection Find .

𝐶 Use cross product: 2 ∙ 𝑎𝑟𝑒𝑎 = Cross product: 𝐵 − 𝐴 × 𝐶 − 𝐴 𝑥1 𝑥2 𝑥1 .Area of a Triangle Have three points 𝐴. 𝑦1 × 𝑥2 . Memorize! . 𝑦2 = 𝑦1 𝑦2 = 𝑥1 𝑦2 − 𝑥2 𝑦1 Very important in computational geometry. 𝐵.

we can decompose 𝑃 into triangles: 2 ∙ 𝑎𝑟𝑒𝑎 = 𝑛−1 𝑖=2 𝑃𝑖+1 − 𝑃1 × 𝑃𝑖 − 𝑃1 It turns out that the formula above works for nonconvex polygons too Area is the absolute value of the sum of “signed area” 𝑛 𝑖=1(𝑥𝑖 𝑦𝑖+1 Alternative formula: 2 ∙ 𝑎𝑟𝑒𝑎 = − 𝑥𝑖+1 𝑦𝑖 ) .Area of a Simple Polygon Given 𝑃1 . 𝑃𝑛 around perimeter of polygon 𝑃 If 𝑃 is convex. … . 𝑃2 .

Conclusion No need to look for one-line closed form solutions Multi-step algorithms are good enough This is a CS class. after all Have fun with the exercise problems … and come to the practice contest if you can! .

- Eugène_s_key_to_the_French_pronunciatio
- Dead Reckoning_ Calculating Without Instruments - Ronald W. Doerfler.pdf
- col11318-1.12
- Summer 2016 ISM 3230 - Homework 6
- Revised Programme 13-07-2015
- Game Report
- bank-stmt.pdf
- 5CS006 Assignment
- Ref for a paper
- 2011. 1002. B. Sampling Fourier
- 1 Managing and Managers
- Chap2-IntAgent
- Awe
- Acalender_16_01_13
- arruboth
- 504635191fa0f6e9af
- Sr1 Toc Intro
- Sr1 Toc Intro Handout
- Sr1 Toc Intro Handout
- SR2_DFA
- SR3_NFA
- 10.1.1.15.308
- 03 Data Structures
- 02 Mathematics

- crypto_ch02
- ch-2(CNS)
- Solid Mensuration
- Machine learning regression
- 4400 Rational Qf
- e20
- Efficient Craig interpolation for linear Diophantine equations and linear modular equations.pdf
- Special Quasi Dual Numbers and Groupoids, by W. B. Vasantha Kandasamy, Florentin Smarandache
- Ramanujan's Congruences and Dyson's Crank
- pnas00708-0046 On Diophantine Equations which have no solutions.pdf
- How to Calculate the Day of the Week
- ac.els-cdn.com_S0377042707002671_1-s2.0-S0377042707002671-main
- 1963-1999
- MC0082
- Number Theory
- TWO FORMULAS FOR SMARANDACHE LCM RATIO SEQUENCES
- On the Smarandache pierced chain
- Algebraic Structures on Finite Complex Modulo Integer Interval C([0, n))
- 5x serial boot rom
- MC0063 August 2010 Q & Ans
- Counterexamples to the Hasse principle.pdf
- k-bonacci
- NATCAT-2-Sol-MA Section.pdf
- May An
- 1347
- scoof
- Dm Relations
- Takagi / Naito's Algorithm Revisited
- Diffie–Hellman key exchange
- Appendix
- 02-mathematics.pdf

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue reading from where you left off, or restart the preview.

scribd