Docsity

Competitive Programming Mathematics Notes | Complete Math Handbook for CP, Codeforces, Slides of Data Structures and Algorithms

Partial preview of the text

Download Competitive Programming Mathematics Notes | Complete Math Handbook for CP, Codeforces and more Slides Data Structures and Algorithms in PDF only on Docsity!

———— 2 (a+b) = ot + Zab + ay ‘ Panets b (a-b) = ot - dab + f coe ae (a-b)(a+b) (arty =o * got + Sob + Distance (A,B) ae c Sy inet) _ Ae OTC Ae CALCULUS ‘ct Numpek THEORY | x : NC eS a ae n ne axb = ") = nent (a,b) = et aas Figs at 241 (mod n) (gea(a,n) = 1) a (sinx) = cos x art 2 af (mod n) & (osx) = -sin x Fy. old) = 1 f vax ‘2 f tax ts Soe “ 10N MATHEMATICAL OPTIMIZATION | ne ‘ ° Maximize / Minimize #(#) sect to a(x) £0, hX)=0 ee a Re Subject te 9 4 | A ComPLeTe REFERENCE FOR ' Comsinatorics alien ae ae Use Lagrange Multipliers | COMPETITIVE PROGRAMMING & PROBLEM SoLvING | oP nl SOU PETIITIVE itiRO.S BATNSING some ROELE Iie H a5) ee a Gri vf =a Vg ri(n-r)! = ce RAMANAND TOMAR of or Zot mide Practice Tovay, “@: CLEAR IMPORTANT PATTERN CoNncePTS FORMULAS RECOGNITION Compete Excet Tomorrow ! Mb & Excer A y Buicp STRONG FUNDAMENTALS. RECOGNIZE PATTERNS. Souve ANY PRoBLem. i4 * Created By Wee 5 n! 20 Cuapters ALL ESSENTIALS ONE HANDBOOK. Nae PROBLEM SOLVING + COMPETITIVE PROGRAMMING MATHEMATICS HANDBook + ay MATHEMATICAL FOUNDATIONS 4) WHAT IS MATHEMATICAL FOUNDATIONS 7 These are the basic building blocks of all mathematics used in Competitive Programming. Strong fundamentals help us solve problems faster, avoid mistakes and choose the right approach. 4) VISUAL INTUITION NuMBER LINE EVEN & ODD oo Ct re: 4, 0) Even =o. eet 0. mS — = + Moving right > fve 2) CORE CONCEPTS > Integers : Positive, Negative, Zero > Even/ Odd: n is even if n%2=0 > Divisibility : a is divisible by b if a%b=0 > Floor & Ceil : Lx] + greatest integer < x ceil(x) > smallest integer 2 x > Absolute Value: |x| = x if x20 else -x > Overflow: Be coreful with 32-bit & 64-bit limits in calculations. FLOoR & CEIL EXAMPLE * Moving left > -ve DIVISIBILITY EXAMPLE Page 4/20 24 is divisible by L3.7] = 3 ceil (3.4) = 4 4,2,3,4,6,8,12,24 [-2.3]=-3 ceil (-2.3)=-2 Because remainder is 0 in each case. Ls.o]= 5 ceil (5.0) = 5 — = — |3) TIME COMPLEXITY OF COMMON OPERATIONS 5) PATTERN RECOGNITION When should I think about mathematical foundations ? Operation Time Complexity Addition / Subtraction 0M) % Problem involves numbers, operations or calculations. Multiplication 01) % You see keywords like : even, odd, divisible, Division / Modulo 04) remainder, ged, Lem, floor, ceil, absolute. bit operations od) * Constraints are large (10%, 10°*) > need to ged (Euclid) O(log min(a,b)) avoid overflow, use long long, mod, etc. Exponentiation (0°) O(log b) % You are doing simulations, counting or constructing Sqrt(n) ot) Something. Log n 01) —— 6) How To use ? v Read the problem carefully. ¥ Choose the right formula / observation. ¥ Always verify with small examples. Vv Identify the type of mathematical operations involved. V Apply it with correct data types and constraints. #) SIMPLE EXAMPLES Example 4: Even / Odd Is 125 even or odd? 125 %2=4 (# 0) = 125 is odd. Is 97 divisible by 3? 97 %3=1 (# 0) => Not divisible. 8) C++ BASICS (TEMPLATE) #include using namespace std; H 64-bit 7 large value H common mod using LL = long long; const LL INF = 118; const LL MOD = 1e9+7; int main(){ ios:: syne_with_stdio (false), cin. tie (nullptr) ; AUP ar ib cin >> a >> b; // Basic operations cout << (a+b) <<" Hf addition cout << (a-b) << Uf subtraction cout << (atb) << 1 multiplication cout << (a/b) <<" Mf division cout << (a%b) << " Hf modulo return 0; } 9) COMMON MISTAKES 11) RELATED ToPics FLow Math Foundations v Number Theory + Combinatorics L Probability ‘ Algebra ‘ Geometry ‘ Advanced Math X Integer overflow (use long long) X Negative module (a%mod + mod) % mod) X Wrong use of floor /ceil X Forgetting type casting in division X Precision errors with floating points 10) BENEFITS / USE CASE V Helps in almost every problem. V Improves problem solving speed. Vv Reduces bugs and WA. V Essential for Number Theory, DP, Combinatorics, Geometry, Probability, etc. 12) ONE LINE REVISION Remember : Tf you see numbers, operations or basic properties... Think > Mathematical Foundations. * Streng foundation makes a champion programmer. Practice > Observe + Apply > Master © |) ce COMPETITIVE PROGRAMMING MATHEMATICS HANDBOOK eS CD, GM & Buciip 2 Page 3/20 1) WHAT Is GCD ? 4) EUCLIDEAN ALGORITHM (FoR GCD) 6) C++ CODE ] 7) WHEN To use ? The Greatest Common Divisor (GCD) Idea : Repeatedly replace the larger number G) GCD (Euclidean Algorithn) ¥ Finding common divisors of two or more integers is by the remainder until remainder becomes 0. long long Cae a, long long b) { V Simplifying fractions the largest positive integer that es while (b != 0) ns aoe divides all of them. [Paareuien) So a La) long long temp = b cir er ¥ Synchronization problems Example: GCD(36, 60) = 12 ro sap lp a elas ge ¥ Cyclic events (12 is the largest number that ; orl } V Number theory problems ivi 24 divides both 36 and 60) Gupsteral b Fea return a} Vv LCM — when need smallest 2 24 4 3 number divisible by all 2) WHaT Is LOM ? 2s ul i ae ae The Least Common Multiple (LCM) a baw la | o «Lem We Gone Slassesmcorees i" cee age 5 mare long long Lem(long long a, long long b) { factor a or Bees e fepeat until b== 0 return (a / ged(a,b)) +b; // divide first (oe ‘ ee = al. So, GCD(36, 60) = 12 } an FS is divisible by f 3) GCD of n = ee ye St Example : LCM(36, 60) = 180 long long gedOfArray (vector Karr) { BCD gees LS 5) LCM USING GCD long long ans = orr[0]; ©, Prctlan slnvolees? coment 2) UKeve REtarroeishre for (int i= 4; i< arr.size(); i++) Be 3 hes, ee For any two numbers a and b : LOM(a, b) = a e gcita,, atti); simplify”, ce xb = GCD(a,b) x LCM(a, b) GcD(a, b) : # Cycles meet again a = a,b) x a, return ans; Events repeat after x,y (Wery useful formula) (Use division first to avoid overflow) } days ee = % Fraction simplification 9) Dry Run Example - GCD(48, 18) tenedieach 40) APPLICATIONS / USE CASES 11) COMMON MISTAKES & “multiple”, “common: - usi roy 7 = | Fraction simplification + 24/36 + divide by GCD(24,36) = 42 + 2/5 X Not handling zero properly multiple" 4% 4+ 2 i DE Y Synchronization + Two machines run every 12 and 48 minutes GCD(a,0) = 0 | al GED ane They mect again after LCM(12, 18) = 36 minutes. ~ ae, Se eae ne Lom 48% 42: LOM = (48/6) x 48 V. Gyelic Events + Bells ving after 45 and 20 seconds + LcM=60 see | | x Quectlon in Caeb) 12 % 6 =0 Stop = Bx 48 | Vv Number Theory + coprime numbers (GCD=4) > divide first = 444 V Reducing ratios + 30:45 + divide by 15 + 2: 3 X Forgetting to take absolute Clemcas, 18) = iw) V Problems involving pairwise /common properties 2 = Ae cn pale a= = —— = . Gohen remainder not updated) 12) E eS Euct. 2 ) EXTENDED EUCLIDEAN ALGORITHM 13) C++ Cope - ExTenpeD EuctiD Dey Run (a=30, b=12) | 14) BENEFITS aon Pro Tip Finds integers x and y such that : long long extendedGCD(leng long a, long long b, Fr ea auc Gan Leaf long, ie, (Ry kann ag) 30 = 2x12 +6 ¥ Very efficient (logarithmic time) Always divide first [Lens by = ged(a, 6) | i (b #20) { x = 45 y= 0; return aj } 12 = 2x6 + 0 ¥ Works for large numbers in LOM formula to Useful in : Example : a=30, b=42 long long x4, yt; ged = 6 v Basis for many advanced avoid overflow: 4 long lon: = extendedGCD(b, a % b, x4, yi); ibui ‘ f Modular Inverse ge4(30, 12) « 6 \ ae F) a y Back substitution gives : algorithms fi iryeh ons & Diophantine Equations One solution : x= 4, y=-2 Cee ATS) aig fal oe 4, yg -2 V¥ Essential in number theory if numbers are very * Crartogrophy | ; Oe: 301) + ie 2)=6 , return gj | Complexity : Oleg min(a, b) (30x4 + 42x(-2) = 6) V Helps in optimizing solutions large. - GCD finds the biggest common factor, LCM finds the smallest common multiple. Related Flow * [15) One LINE Rewsion| Use Euclid for GCD and the formula for LCM. @cD > LOM > Extended Euclid» Modular Inverse -> Diophantine Eq. ComPETITIVE PROGRAMMING ee AE oe * 4. Divisors & NUMBER THEORY # Page 4 / 20 1) Divisors (Factors) 3) NuMBER oF Divisors (d(n)) 4) Sum oF Divisors (o(n)) | S) PERFECT, ABUNDANT, DEFICIENT 6) C++ Cope TEMPLATES A divisor of a number n is an integer d Tf prime factorization of n is Tfen=ipy xipe ee pe Y Let S(n) = Sum of proper divisors (excludingn).| | (2) AU Divisors “ such that n %d = 0. n= pm x pet x... * pam Then sum of all divisors Sue ene long) { e ae, aren vector ans; Divisors come in pairs (d, n/d) ‘Then ruitbier, ofldRisors r = Tf S@) =n Perfect Number Gord longgioea Sie Le ee Example : n= 36 ae Gaara eal an) = TT (pe = 4) TaStasir sal Atnderk® Wonka # (aise 0) { eal d(n) = (a, +4) x (a, +4) * Oy, +4) ef pod me ans. push_back(i); Doiters + (8, 2,3,4,6,9, 12, 18,36) a 2 push tet [belles F pees | TASC iin Bet scene) eet (i 9/1) ons.pushback(n / i); Example : n= 360 Exomples : } 2) Finp Att Divisors Prime factorization of 360 6 divi 4, 2, 3, 6} : |= ies, Gap divtseraYaatt, 27185 sort(ans.begin(), ans.end()); ‘ ali Es seesrever , 3 Tdea : Check up to Yn, add beth i and n/i aon anes" S(6) = 142+3=6 — Perfect return ans; Example : n= 36 = (Bet) x (204) x (4+ ample : on (360) + (361) x (204) x (404) one 12 > divisors * {4,2, 3,4, 6,42} ‘ee i [sexi] Pair ~ 4x 3x2= 24 | cs i Wvisors 4 138 | ape ea | Sti2) = 46 > 12 + Abundant lenillenay caaneEiceove( katy Ley ned ‘2 2 List + (42,3, =a se 13 + divisors © (4, 43} rad het a o | Gate when : or p> 2; pep < nj pe Use when : S(43) = 4 < 13 + Deficient ‘ 3] oo | a1 areyys42, % Counting number of divisors bits ee: # (nXP == 0) a | aE ar? # Sum of divis bles int exp = 0; {0 | os 48, 36) 1 Problems. on highly composite. numbers : a % Koown fact : Pine ye nore Cah s| 4 = % Optimization problems a anaes eee gabe A rumber is Perfect iff it is of the form ent #= (exp + 1); 6 | o | «6 i Optlanization’ /g DE tronwitioes 2°* (2% -4) where (27-4) is prime. } Time Complexity : O(n) | Ex : 6,28, 496, 8128, ... if (n> 4) ent *= 2; fate | return ent 3) «Prime FAcToRIzaTIon (RECAP) 8) PROPERTIES OF DivIsoRS 9) Dry RUN EXAMPLE — n= 72, = To = 22x 3? ComMON PROBLEMS WHERE USED fo apply formas of d(n) and o(n), Pts TCE F2= 2? x 3 [ 10) we need prime factorization. a] vaxi | Par addea PsA I % Find number of divisors of n. Example : n= 360 w Niarbser:’of idlstsors Ns, aliseass oa) ‘cet (4, 72) oc 42 ||| % Find sum of divisors. ro if nis a perfect % Find all divisors ond perform operations. @1 360+2= 180 360 = 25x 32x 5! ree ae 2 $ (CHS) 3 36 32) a fai r — 3 ° (3, 24) {4, 2,3, 24, 36, 72} (hao (et | % Find smallest divisor greater than k. @j] 180+2- 90 ¥ Sum of divisors is multiplicative “| | g(72)2 @-1 , (nt ne = : ce es (4, 48) {4, 2, 3,4, 18, 24, 36, 72) a 32d Find largest proper divisor. @ 7 w+2- 45 5 if ged(a,b) = 4. 5 2 —_ = X Check if number is perfect / abundant. Gy] 45 +3= 45 ¥ oleb) s6¢a)inio(b) 6 | ¢ | (6,42) | 4,2,3,4,6,42, 18, 24, 36, 72} 848) X Number theory + DP optimizations. e 15+3= 5 a * 7 2 a = = 495 % Problems with ged/lem relationships. O oao- 2B saben ia) prin aieacteors, = (475) 8 ° (e, 4) (4,2,3,9,6,8,9,42, 18,28, 36,72), L 41) Common MISTAKES { 42) Benerrts 13) Pro Tie 44) ONE LINE REVISION z|| 45) ReLateD Flow X Forgetting to handle n= 4. Reduces complex problems to small building blocks. | 2 re A Understand divi: Number Divi X Counting n twice when i= n/i | Helps in optimization and counting. gel eit caged a | at pans a ai, APs ec neny nec): | ¥ Essential in many advanced algorithms | Then use formulas. i ||| > CAR ents . | [Boar] Prine zone |S X Not using division first in LOM. (NTT, CRT, DP, graphs). | | ( + Precempute SPF up to 108 factorization & properties Foctorisntion | | (Sum of, Diviners to factorize in O(log a) time. —> Solve smart. a re i | Important for number theory & cryptography. | o | on) eae me ie 2 aN | Divisors tell us the structure of a number. Factorization is the key. Learn — Practice — Apply. ComPETITIVE PROGRAMMING MATHEMATICS HANDBOOK * 6. COMBINATORICS # 4) WHat Is ComBinaTorics ? Combinatorics is the branch of mathematics that deals with counting, arronging ond selecting objects under given conditions. Tt appears in many CP problems involving counting ways, probability, DP states, etc. 3) FactortAL (n!) nie de2e3xe...xn (nz0) ole a Example : 5! = Sx4x3x2x4 6 120 Common Facterials Key words : choose, select, arrange, distribute, ways, number of ways, how many combinations, permutations, ete. 2) ADDITION vs MULTIPLICATION PRINCIPLE Addition Rule (OR) Tf a task can be done in x ways or y ways, then total ways = x + y. Multiplication Rule (AND) Hf @ task can be done in x woys ond another in y ways, then total ways = x xy. { Example = tua Choose one color from 3 colors and 40) STARS AND BARLE Number of ways to put k identical items into n distinct boxes = “*""* c,. Example : Put 5 identical balls into 3 boxes. 3*8e8 ce =o cues 24 Visualization : x * kk * Se ee Box 4 Box 2 Box 3 —s o|:|alala|s slo | 10 T lecal + |=] 2 [6 |94] #89] 729] Sensi] aeaae | 362880 3628800 Factorial grows very fast! Use precomputation + module Page. 6/20 4) PERMUTATIONS (ORDER MATTERS) Number of ways to arrange r objects out of distinct objects. nt (n-r)! i (osrsn) Example : Arrange 3 students out of 5 51. 420 (5-3)! 2 = 60 *p,« iol Coase : "Pp, = nl (arrange all n objects) "PRs 4 (arrange zero objects) 5) COMBINATIONS (ORDER DOES NOT MATTER) Number of ways to choose r objects out of nv distinet objects nl "c, =| ———— _} (eoéran) ri(n-r)! | Example : Choose 3 students out of 5. Sc, = So! 5 420 5 40 Stat ex2 Special Properties ov 4 aa a | VAG, menGany, v y= “Cg + “AC, (Pascal Identity) [2 BinomzaL Theorem For any real number a,b and non-negative [ faye Boge 0 Example (x4+2)% = "Cox? + *Cyx?2 + %e,x0? + 2c,29 of s xP + 3x2(2) + 3x(4) + 8 = x3 + 6x* + 42x48 41) Common Use Cases Counting subsets / partitions Graph coloring, matchings, etc. ee ae Y Counting ways in DP transitions VY Probabilit lems. v ae Re problems 3 ¥ Distributing identical items II \isccecem ce ¥ Combinatorial Game Theory "ea a v ee 42) DRY RUN EXAMPLE 8) nCr MOD p (p is prime) * When n is large, factoriols overflow. + Use Fermat Little Theorem for inverse. "C, mod p = = Cnt x inv! ‘% p x inv((n-r)!) % p) % p Where invix) = xP? %p (by Fermat) Use precomputed factorials and inverses for multiple queries At psir (2) Gs) (4) Gus) Paaale (2.2) G4) @s) Ga) aiyst Sate 10 Gs) &,5) 13) PATTERN RECOGNITION “How many ways to choose” —+ Combinations % “How many ways to arrange” -» Permutations “Order doesn't matter” — Combinations “Order matters” —+ Permutations “Sum of values” + Use combinatorics + DP | Combinatorics ic the art of counting wisely. oe Think > Count > Simplify — Selve. “Distribute identical things” > Stars and Bors 44) COMMON MISTAKES X Using at Forgetting O! = 4 Wrong r value in formulas Overflow without modulo Using division instead of modular inverse Not handling large constraints instead of nCr or nPr a a ae ard 15) BENEFITS e RORS Ss ase Find number of ways to choose 2 books from 5 | | | | 9) C++ TemPLATE (mcr MOD p) const long long MOD = 4¢9¢7; oe ! const int N # Ae6+5; ! long long factEN], invfectlNI; pret: oc) long long medpew(lang long a, long long b) { | Query : O(4) long long res = 4; hile) { ame if (bR4) res « (res#a)%MOD; a= (asa) #MOD; ee ch ) ay } void init € facto] = 4; for Gint is4jieNyier) FactLi] + factLi-a]einmon; invfact(N-4] = modpow(factiN-1], MOD-2); for Cink i2N-2; i280; i--) invfact(i] = invfactli+i]«(i+4)% MOD; } long long nér (int n, int #) if (r Apply smartly + Solve fast! [ 17) Retared Flow K al cae ri (n-r)! Combinations SS S| (Page 6) is = COMPETITIVE PROGRAMMING MATHEMATICS HANDBOOK eee * 7, ADVANCED COUNTING # Page 7 / 20 4) CATALAN NUMBERS Catalan numbers appear in many counting problems involving structures, recursion and Visual (ne3) Formula «Q)) (nz0) (OQ) First few: 1, 4,2, 5,44, 42, 432, (QO Common Occurrences + ) 0)(4)) ’ Nantar of anys to coy mach pornthess | Octo YY Number of BSTS with n keys Y Number of ways to triangulate 2 convex polygon with (n02) sides ¥ Dyck paths, non-eressing chords, stacks, ete |Tatah » 5 =Cy = Example : Number of correct parentheses strings of length 2n. Answer = Cy 2) DERANGEMENTS (!n) Number of permutations of n objects such that no object appears in its original position Formula : z facto : py k! First few: 41,0, 4, 2,9, 44, 265, . Recurrence : tm = (net) x (1(n-4) + '(n-2)) (ne 2) || Bose: to+4, 420 | | Example : 3 people sitting on 3 chairs so that no one sits on their own chair. {13 = (3-1) x (12411) = 2% (+0) = Visual (n= 3) 283 © @ 192,243, 344 Choirs 13, 254, 3-42 5) MULTISET CouNTING Objects may be identical. Order may matter or not G) Permutations with repetition (order matters) If counts ef items are c,, ce, | Example : Arrange letters of “MISSISSIPPI” (Met, Tet, Se4, Pe2) (ned) aa Answer = atargi 7° 341650 Gi) Combinations with repetition Corder doesn't matter) | Choose + items from n types (infinite supply) | peerXe uf Example = = le —_ 9) ADVANCED COUNTING PATTERNS — WHEN TO USE WHAT? 10) Day RUN EXAMPLE ~ Inclusion Exclusion 11) Common MrsTaKES 12) BeNerits 13) One Line Revision Prblen Tyre ~The Att oy Techigues feeeeleeskerles iee sokene ter as © Usngiil ssokaallish nly) or ae a Oy Set I a X Forgeting identical items ¥ Solve complex counting problems Count smartly. Syrnatry / rotations / reactions | Dotnet eninge / rope | Burwide’s Lanna ipl a zee eel a | pide aie Ses Mes Essential for DP, NT, Prob, Graphs ee ee Tistribate identical tema Conds, balla, Matis | lich Comting ease she a ie Weald V Helps in optimization problems | ay . Count scores STs, prethenes, paths | Catalan Numbers Ane | : || moe < Y Used in almost Picts: | | ~ APs) forme ioe eens — = : Fe || | ane 3 | [anawer = 1521046 ||| % Not considering symmetry yet : . ~ Answe | [oP opkinination ae en ea ra | We | gor | | eee etae Ne 2 | reas ee alee: pea) tes : EE — fi, ae i ae | X Overflow in large factorials / combinations | * ls) “BURNSIDE'S LEMMA (INTRO) Answer = (16 +244 + 2) Used to count distinct objects under group actions (rotations, reflections, permutations) Where : |G] = size of group (number of operations) Fix(g) = number of configurations fixed by operation g. Example : Number of distinet colorings of square’s vertices using 2 colors (R, 8) under rotations Group G + {0*, 90%, 180, 270°} (IG = 4) Count Fix(g) : #07 rotation + oll 2" = 16 configurations # 90" rotation + all vertices same —+ 2 configs (RRR, BBBB) 1% 180" rotation + opposite vertices same + + 270" rotation = same as 90° = 2 configs 24 = & configs + 6 distinct colorings ane | | | L_ Geeffieient of 2 = _(Rivonced Courking turns tough. =e inte spe math. 3) 1 INCLUSION - ExcLuston PRINCIPLE (IEP) Used to count the size of union of multiple sets For 2 sets A, B [AUB = IAL + 18] - [ANB] For 3 sets IAUBUC] = JAl + 1B + ICl = AaB] - 1BACI - [ANCL + lANBAC| 4) PIGEONHOLE PRINCIPLE Basic Principle : If n objects are put into k boxes, then some box contains at least [2] objects. Generalized Version = | If nv objects are put into k boxes, then some box contains at least | v4 le [== objects where | ae eee at most (m-1) objects can be | x Subtract pairs in each box. eae ee | Eeaeotae, Ace 413 people, % Subtract quadruples ... (alternating signs [ZZ] Add ——_ 8 ae Me oe ¢ cae EA there are at least 2 people whose Example : Count numbers from 1 to 400 divisible 2d (He er ee by 2 or 3 or 5 (m= 43, k= 412 months) 100 l= [192] =o | ansie te tanci «sto ais t= (282) «33 | isnei «66 reer @ a When cbjects > bexes lel = (121s IAnBacl = 3 Prove existence | Answer + 50433 +20 - 16-10-6+3=[74] 2 7) GENERATING FuNcTIoNs (BASICS) Powerful tool to encode sequences and solve counting problems If Go) Gay Qxy ove i @ sequence, is generating function is GOe ecueenee aceae wane | y Properties : Addition | GtH + coefficient wise sum ¥ Multiplication : GxH + convolution (combinations) Example : Number of ways to choose any number of items from n distinct items. Each item either taken (x*) or not (x®) G(x) = (+x) (1) A cheese ke items | Find dupticotes / collisions Useful in proofs & puzzles L = =) =a a") Aer) COMBINATORIAL IDENTITIES «Peat taming (2) + (rt « vetomonte SCE) (ate) pale) oles (eye) Zale) a? Use these to simplify messy expressions fast! Symmetry: ¥ Sum of Row : Recognize patterns -+ Use right tool + ComPETITIVe PROGRAMMING MATHEMATICS HANDBOOK ea Ee Se Ei oak kee 4) WuaT Is MaTRIx ? A matrix is a rectangular arrangement of numbers (or elements) in rows and columns. Example 4 A 2x3 mabrix (eles, A dt ahs | 4 5 6 L ee | 4) MATRIX OPERATIONS | @ (i). Multiplication ey 44) DRy RUN EXAMPLE - FrBonacct (n= 5) 14 omy Fa mee e-[t ft] om [ For n= 5 + Qt *& Think in MATRICES. Fas Fea ] So, Fe - (@*), = 5 Fibonacci : 0,4, 4, 2, 3,5, + 9. MATRIX MATHEMATICS + Page 4 / 20 Matrices are powerful tools to represent and solve complex problems in graphs, DP, transitions, transformations, and more. Fast | | Compact + | 5) MaTRIx MULTIPLICATION — VISUAL EXPLANATION A (2x3) B(x 2) 22) | ah € (2x2) a}2]3 | x | aso] = ||a]sle | aa | 42 2 Power oF Matrtx (A‘) | + Used in DP transitions, Fibonasei, path Use MATRIX! + Powerful Cie2) SE? ay = $8 oD (in), >. 64 (as) 6 439 (and) + » = 139 ee eee Build Strong Foundations. (aB)" = BAT |) 2) Mareax Exponenrratzon (Fast Power) | 2) Baste PRoPERTIES 3) TyPes of MATRICES 7 VY AB B+A + Square Matrix: nxn ie ‘| 4 (ov A+B) +O © A+ (B+) + Identity Matric (I) : act | v ABC) = (aB)e (Associative) oar [: al Y ACB +) = AB+ AC ah Teco nate LO anus Carats tote + Diagonal Matrix : All non-diagenal FET ak (Transpose) elements = 0 v + Upper / Lower Triangular Matrix UT Cee» Matrix Exponentiation (A*) const int N= 2; // change for nxn using U = long long; using Matric = vectorévector >; Matrix multiply (const Matrix 6A, const Matrix 88) { Matrix C(N, vectoretl>(N, 0); int keO; kx Ns ke*) CLUDES) + COLLIE) + ACAICK*BCKIEED) % MoD; return Ci } Matrix power(Matrie A, long long k) { Matrix R(N, vector(N, 0); for(int iOjixWsier) REG) + 45 while (20) { (KE) R= multiply(R, A); A= multiply(A, A); W Tdentity + return Ri + Symmetric Motrix : A = AT | 8) PATTERN RECOGNITION Repeated transitions / steps Sequence problems (Fibonacci, DP) | | & Counting paths in graphs H State transitions in DP ‘® Linear transformations / rotations ® Markov Chains, probabilities | System of linear, equations 9) WHEN To Use ? Vo Many repeated operations VY Transitions depend on previous. states Yo Need fast computation for large k ¥ DP with fixed states (matrix form) ¥ Path counting / grid problems 40) BEeNEF&Ts Compact representation Fast computation with exponentiation Used in many advanced algorithms Essentiol for DP. optimization Helps convert complex problems into simple matrixe operations nea 44) ONE LINE REVISION Fibonace: & Linear recurrences Counting paths in grids / graphs Markov Chains & probabilities DP optimization (state transitions) Cryptography (encryption, hashing) Computer Graphics (transformations) Solving linear systems kovee 45 One matrix con save your TLE! Solve Hard Problems EASILY! Model os Matrix ComPETITIVE PROGRAMMING MaTHEMATICS HANDBOOK [» WxaT Is A PotynomraL ? A polynomial is an expression of the form 2) Baste Terms. | + Degree of P(x) = highest power of x with | 3) PouyNomIAL OPERATIONS Addition / Subtraction Plx) = agx™ + Oi xh? +o. + 04x + Oo | | non-zero coefficient. + Leading Coefficient = coefficient of x™ Add / subtract Uke terms. where a, are coefficients (constants) and ni is @ noncnegebive integer. P(x) = 3x" - 2x3 + 5x - 7 P(x) = 3x% - 2x + 5 Q(x) = x3 + 4x7 - 7 + Constant Term = value of P(0) + Zero / Root of P(x) = value of x for which P(x) = 0 sag asset agents enti gem att | (ax* + 3x4 4)(x- 2) = 2x9 = 4x? + 3x* - 6x + x Know the terms well, | | | a Solve the problems well! ©) = ax) - x4 - 5x - 2 (ii) Scalar Multiplication ihe i lending dagree canton | coefficient 4 term 6) Division oF PoLYNoMIALs Divide P(x) by Q(x) P(x) = Q(x). Quotient(x) + R(x) where degree of R(x) < degree of Q(x) | Long Division Methed (like numbers) a oe G2 - ax + 3x-5) + (x-2) 2 x 3 q x-2) x® - ax? + 3x-5 2 2 “3x - 5 3x -6 L a5 1 — _ LR PG) = kame” + konea2 == 8) REMAINDER THEOREM If P(x) is divided by (x- a), the remainder is P(a) Example + Find remainder when divided by (x - 3). 7) Factor THEOREM If (x= a) is a factor of P(x) then Pla) = 0 (and vice versa) Ajax? Garde Rai ie - ata e)| Plx) = 2x2 - aah x 5 || Check of Gx = a factor. f (x- 2) is a factor, ages (RCS) = 227) - 30) +345 = 54-2748 = 35 P(2) = 8-16 +2+6-0 Yes, (x -2) is o factor. To test (x-a) is factor + Pla) +0 Super useful in competition! J| 11) Sum anp Propuct oF Roots |) foerquamratie van? + iba e.=if0 | aie notte ey | «B z | Sao es =|! = a 13) PotyNomzaL MopuLo (Mop) | Used in NTT, FFT, Hashing, ete. Two polynomials are equal under mod M 12) SyntHeTic Diviston (Fast!) Divide P(x) by (xa) quickly. Example : Divide x - 6x*+1ix-6 by (x-2) eS ee eae teres || sf oll coefficients are equal mod M. Gilere ere ret nes Example : (x24 2x63) = (x2 + 2243+ 5m) 2 -3— 6 (mod. M) : 4 yh ae Operations are done coefficient -wise Quotient Coefficients Remainder || under motile. (P(2) = 0) (ae haan ito Quotient = x? - 4x43 | alaastermescencet "ger * 10. POLYNOMIAL MATHEMATICS # P(x) + Q(x) = 4x* + 4x? - 2x - 2 Multiply each term and combine like terms. Page 10 oh 20 4) EVALUATION OF POLYNOMIAL Find value of P(x) for a given x. Example : P(x) = 2x>- 3x7 + x44 P(2) = 2(8) - 344) +244 = 46-12 43=7 Use Horner's Method for tes fast evaluation | + kag | J — | 5) Pouynomza IDENTITIES V (x+y)? = xt + 2xy + y? v (xy)? = x? - dey ty? VY (x4 y)Ge~y) = x* - y® (xy)? = x8 6 3x%y 4 day? + y? Vo (en y)® = x? - 3x8y + 3xy?- y? 4 a gt = (eaylat= ay ey | vox = yg = (x-y)(x? + xy + y7) 9) FAcTORISATION TECHNIQUES + Common Factor + (Grouping, . Using Identities Quadratic Formula (for ax* + bx +c) -b+ VbF - doc 2e xs + Factor Theorem + Difference of Squares / Cubes ja 44) Porynomrat INTERPOLATION (Basics) | 45) Given nv points (x,, yi), find polynomial P(x) of degree < nv such that P(x) = yi for all i. (Used in mony CP problems) | Lagrange / Newton Interpolation are common methods _— al | 10) PoLYNomIaL Equations Solve P(x) = 0 Example : x*- 5x46 = 0 (x- 2) -3) = 0 x= 2or x=3 Solutions (roots) are very | Uses / APPLICATIONS DP Optimizations (Convex Hull. Trick) NTT / FFT (Polynomial Multiplication) Combinaterics (Generating Functions) Hashing (Rolling Hash of Polysomials) Geometry & Algebra Problems Polyromiols appear everywhere * Polynomials turn COMPLEX PROBLEMS into SIMPLE EXPRESSIONS. Learn + Practice + Master + Conquer! ComPETITIVE PROGRAMMING MaTHEMATICS HANDBOOK = 4) WxaT Is A Vector ? + A vector is a quantity having both | magnitude and direction + Represented by —> or bold letters. Example ¥ Zs Lax, ay) a ay ! [a] = magnitude Direction = angle @ with +x axis x ° Oy 6) Progection Sealar projection of Z on | comp, = | : Q | Vector projection of & | a Ji Three vectors &, 6, we (a Kw 2) Baste OPERATIONS | + Let &* (a,,a.,0,) GW Addition B+ - (arb, Gi) Subtraction » Bs Cb be. eathe, ae by) 12. VECTOR GEOMETRY 3) Dor Propuct (Scatan Propuct) | bs) © &-B is a scolar, i Bis aah, oagbyysvagbi | + [8] |B] cose Sa £ Z-B + a-b&, a-b, a,-b) (ii) Scolar Multiplication [Wes eatin; . ka, , (iv) Magnitude (Length) = la] « far + az + af Z) CorLaNaR Vectors 3 ore coplanar || (fz) -0 Scalar triple product (Volume) kas) 2 = Properties YE-B - E-S (commutative) YE (B42) FB e k-S (distribuding) jive a+ al? Ir LIne IN VecToR For" A line passing through point #, in the direction of 2 FeHead, veR [ta zg ayt-os, (xz) | 9) Plane IN Vector Form A plane passing through point #5 and having normal vector #% + fa Cross Propuct (Vector Propucr) |! 5) ANGLe BETWEEN Two Vectors + ZB is a vector perpendicular to both & and 6. ne: ow as hs thee ih | [exB] - 181 [81 sno abit » | i | + = 90° = vectors are perpendicular ) ~ rc | z | (EB +0) Propertins | + @ = 180° vectors are in site Fait: - ecb) a as Vaun(Buz) - B(a-2) - 202-8) |i vaxa +8 Ht = r direction (@-B < 0) 40) Distance Formutas (@ Distance between two points AZ) ond BCE) a. #.) +0 Where, z F position vector of any point be = ; he Tie, ¥ — position vector of any point (@) Distance of point P(#5) from = fon the plane. on 7 z - plone H- #4 ds 0 ~ i eo z a i ' = ' 2 * ° as | comp, & 6 L = J - Jt 11) INTERSECTION oF LINE AND PLANE 12) CouLinear PornTs | 13) Section FormuLa (Vector Form) 14) Uses / APPLICATIONS Une : Fe Reeund z 2 Three points AC), B(B), C(z) are collinear Tf P divides AB internally in the ratio m:n, % Path planning in robetics / games s fia Reavis, es iar = = ns ve = i at (i(0 = 2), (2a) 2 pe mbtné Geometry enters tine? fe mon Physics © forces, velocity, epncorans | 2D) == EASY ! - a % Computer graphics & animations a Ata) Be) cle) ne : Re Many CP geometry problems! 2s —— JL = J — ns = . : . "| * ‘ VECTORS give you DIRECTION. FORMULAS give you POWER. PRACTICE gives you VICTORY! | * aes = : z “ ComPETITIVE PROGRAMMING MATHEMATICS HANDBOOK e 4) Wxat Is A PotyGon ? + A polygon is a closed plane figure | formed by joining a set of straight line segments + n= number of sides (m2 3) |/EserreleCHatagee) i: A B | F c E D t &) DIAGONALS IN A POLYGON Number of diagonals in an nesided polygon 2) Sum oF Interior ANGLES + 13. POLYGON GEOMETRY * 3) Sum oF Exrerion Anates For an n-sided polygon, For ony polygon (one at each vertex), Page 13/20 ry — INTERIOR ANGLE (Requiar Parton) {5 Each ExTeRIOR ANGLE (REGULAR PoLYGon) Tf all sides and angles ore equal, | Hf polygon is regular, | Sum of interior angles 2) x 180 Sum of exterior angles * 360° | (Always constant) Example | Seeenete arabes his Pentagon (n= 5) Sum = (5 - 2) x 180° = 540° Hexagon (n= 6) Sum = (6 - 2) x 180° = 720° ke { POLYGONS | are) If PURE LOGIC in » GEOMETRY ! s 7) TRIANGULATION A polygon of nm sides can be divided into (n - 2) triangles by drawing diagonals from one vertex. Example (Pentagon, n= 5) Triangles = 5-2 = 3 ( \ ( ( \ " A Diagrary ( Understand Shopes. | E B || Build Strong Foundations Solve Any Problem ! @) D ie — J # Tongle (n= 3) *® Quadrilateral (n = 4) * Pentagon (n= 5) * Hexagon (n= 6) * Heptagon (n = 7) * Octagon (n = 8) 10) TYPES OF POLYGONS | (i:) Convex Polygon | AU interior angles < 180° | (a) Concave Polygon Ak least one interior angle > 180” 11) ImporTaNT PROPERTIES Y Sum of interior angles = (n= 2)*180" | 6 Tangle (n= 3) 42) Spectat Poryaons (FoRMuULAS) ea _ (n= 2) x 180° _ 360" Each interior angle = S075!" TSO. Each exterior angle = ——— Example + Example Heptagon (n = 7) Octagon (n = 8) Eackwargte..o) Seam inaliot || ach exterior angle = 222 = 45° 7 Diagram = OO 6 2es7 | = 7 Diagram 8) AREA OF A POLYGON 9) PERIMETER (Using Triangulation Area = Sum of oreas of (n- 2) triangles (iW) Using coordinates (Sheelace Formula) Perimeter = Sum of oll sides Regular polygon (side = a) For vertices (xs, yp), (ea, Yad) -o-1 (Ens gad Perimeter = on x =| Example Areas 4 & (agian = Hist gi) wee aera whore Cineve'Yard = Geis te) Perigaiter sire Example (Quadrilateral ABCD) Diagram : ACx,, ys) Bora, ya) C(x, yy) Dlx, 9) 13) PotyGon IN CoorDINATE PLANE 14) Uses / APPLICATIONS Vertices given as (x, 4.) a * Graphics & Computer Vision v a of aoe = 3605 Sum of interior angles = 180° + Perimeter -+ sum of distances #® Game Development (collision, shapes) ¥ Diagonals = * Quadrilateral (n= 4) between consecutive vertices V Triangulation = n - 2 triangles Sum =p 366%, Dinguale- 2 %* Robotics (path planning, areas) ¥ Tn a regular polygon, ' ene) ar Aree Sit Sehotleed, fsrrestal % GIS & Map systems Pa dacs aah el oe > Ae ase gl Sum = 540° , Diagonals = 5 # Physics & Engineering ask aiatertor, angle’ {n-a}ater * Hexagon (n= 6) %* Competitive Programming Problems * Each exterior angle = 360° Sum = 720° , Diagonals = 4 ———— ———— —— ee SHAPES _ build "INTUITION FORMULAS | build ‘POWER, PRACTICE builds MASTERY ! © ; * ComPETITIVE PROGRAMMING MATHEMATICS HANDBOOK * 15. GAME THEORY + Page 15/20 4) WHAT Is GAME THEORY ? + Study of strategic decision making between two or more rational. players. | + Each player's outcome depends on everyone's choices. + Solved using tools like Nim-sum, Grundy number, Sprague-Grundy theorem. Applications : + Combinatorial Games + Competitive Programming + Puzzles 1 2) Tyres oF GAMES 3) WINNING POSITIONS + Impartial Game + All players have same | (ii) Sprague-Grundy Theorem : eet ony Set A position is winning (Pi) if SG value # 0. + Partisan Game + Players have diffrent || 4 postion is losing (Pa) if SG value ~ 0 moves. + Deterministic Game : No chance. sg(a@bo...@2) | * Game with Chance : Probabilistic. Example + Perfect Information : All moves visible + sg(0) = (losing) + Imperfect Information : Hidden + sg(1) = 4 (winning) + sg(2) = 0 (losing) i 4) NIM GAME * Many heap piles, players remove stones from any one pile. The ia Paling ae oa Winning condition : Nim-sum # 0. 5) CLEANING GAME (Hexagonal) qj + A stone is removed and neighbors are connected / game changes. + Use connected components to Find winning position. | ing Pes | Nintaumuaraleiake. ole | Tf Nim-sum = Else -+ N-position (P1 wins) — O - P-position (P2 wins). | saloate] 4 Gundy nanber | SG (state) = mex {sg(next state) } 6) Bout “GAME | at | + If total stones mod (m+1) = 0 -» P2 wins | + Else + Pi wins + Two players take last stone from bag. | + Tf final stone removed by Pl + PA wins. | Ifa 8) GRUNDY NUMBER (MEX) 7) CHAIN GAME + Players remove a block of stones + mex(S) = Ninimum excluded number + Consider os impartial game. Eormple : | Mex trick : | + Compute $6 for each sise + XOR them to get final sq value + Tf sg #0 > PA wins else P2 wins. $= {0, 1,3} = mex(s) = 2 ° 4 = SG(v) = mex (SG(Child of v)) Jt 3) TREE GAME + Node game on tree. + Grundy number computed bottom-up. [Method : 1. Compute sg for all children 2. sq(node) = mex (child values) 3. Root decides winner. | Explain: binary tree, path game ete | 11) SUBTRACTING GAMES + Remove k coins from heap (ke set), + SG reduces to Grundy number. | es ae independent. + SG values are small. a) GAME STRATEGIES + Brute-force / minimax (two players) + DP on subsets | ExacT CoveR GAME + Choose disjcint sets to cover. | 2 Use DP / state compression. || Inclusion -+ Exelusion style game theory | + Model states as masks. | + Greedy (in some special cases) + SG theorem for impertial games [=r] x ‘a Game Theory — ; Problem Solving + SG on 2" states possible. * Look for xor / parity / coloring tricks + Moves repeat iiblaicas \| a lees = | NIM EXAMPLE BouT GAME EXAMPLE ‘SPRAGI Gn Tee | A B D m= 3, total = 6 | +1) = s i | {e] | 6 mod (3+1) 240 — PL wins | Nim-sum: 304@5@6-=2 (#0) O000 | [Make total med (m+1) = 0 -+ P2 wins! | = Vf f SAMPLE PROBLEMS. + Stone Game (LeetCode 877) || + Grundy Number (SPOz) || © Winning Move (CF) || + Tree Game (CF) || + Lights Out (LC) IL = = i SG VALUES 071-2-73-4.. Moves set | Grundy number | a} ar {1,2} {1,3} {2,4} {1.4.33 Wee a ae he into “Strategic Tear aed + Nim Game | if 10) LCF GAME | + Move coin on graph by one vertex. + bose iF stuck Winne: Condition} [ ¥ sg(stort) ¢ Else + Lose Oo + Win = "Key TAKEAWAYS ] Y Identify game type first | ¥ Use Grundy numbers for impartial games ¥ Nim-sum gives final answer for XOR games ¥ Use mex function for SG computation ¥ Look for independent subgames v rafrasie oth lens rin, toe (S} oo =] f \f Games. = Manes + Srnarear * Think beyond brute force. + Spot patterns + Use Xor / mex / parity + Practice. on real problems ieee eee J * CoMPETITIVE PROGRAMMING MaTHEmMaTIcs HANDBOOK 4) Moputar Inverse For a,m coprime (ged(a,m) = 1), the modular inverse of @ modulo m such that is ot 1 (mod m) Ways to find. + Extended Euclidean Algorithm + Fermat's Little Theorem (if m is prime) ot a™* (mod m) Example: 3°* med 41 = ? 3-4 = 42 = 4 (mod 44) So, 3* = 4 (mod 44) 6) Lecenpre’s Tueorem (For Parmtes) For prime p att (3) (mod p) Where (a/p) is the Legendre symbol. 1 if ow quadratic residue mod p (ajp) = 4-4 fa ie nonequadratic residue mod. p © € pla Bisirple x ip isr 7 at = a* = 27 w 6 wt (mod 7) $5 (3) = -1 (non-residue) 41) Pamme Factortzation TrreKs + Triel division up to Yn + Sieve of Eratosthenes (primes up to N) + Pollard's Rhe for large factors Example | Factorize 84 84 - 2-42-2-2-a1- 2.367 , aad | Prime factorization is the foundation \ ) t (tes number theory algorithms! @) * 16. ADVANCED NUMBER THEORY * 2) CHINESE REMAINDER THEOREM (CRT) For pairwise coprime mg) mayo) and remainders ay, @2) 0, On, the system: ein; Atmadiens)) x ® a, (mod m,) x = ay (mod my) ke has o unique solution modulo M = |] mi Example x = 2 (mod 3) = = 3 (mod S) x = 2 (mod #) x = 23 (mod 4105) | 7) Quapratic Resrpues An integer a is a quadratic residue mod p (p prime) if Bx such that x? ee Geaaip) Half of the non-zero elements ore quadratic residues Example: pos 11 Squares modulo 44 s204, 2224, 3749, 4725, 5223 Quadrotic residues: { 1,3, 4,5,9} 42) Sum oF Drvisors o(n) peas TT ph, then ket ae) = [28 tpt Example: ne 42 2 27.3 2 EEN eee ee le ETT - ae i Dwisors of 12 ore 4,2,3,4,6,42 (sum = 28) 3) ExTenpep EucLIDean ALGORITHM Finds ged(o,b) and integers x,y such thot ax + by = ged’a.t) | Use + Modular inverse + Linear Diophantine equations (ax + by = ¢) + Solving congruences Example: ged (30, 18) a b ahb 30 18 42 18 42 6 12 6 oO ged (30, 18) = 6 Back-substitute to get. 30x + iBy - 6 i) Discreve LocartTHm (Baby-Step Giant-Step) Given g,h,p (p prime). Find x such that 9” = h (mod p) Algorithm (BSGS) sts m= (4) + Boby steps store (q’modp, j) for O« j 0) a+ (aca) %m be boa return res te «NUMBER THEORY is the ART of FINDING PATTERNS in INTEGERS. exponents! (b& 4) res = tess dim O 4) Eucer’s Torient Function @(n) ln) = number of integers in [4 n] that are coprime ton Properties + If p is prime, o(p) = p-4 + phillin

0) —— (Pte alae pf O} UNDERSTANDING 4) LocarITHMs log, (xy) = log, # + logy y tog, (3) = log, = = boa, y logy Go) =k logy % tog, = tog, = tops & os ene ae ae asd, log 1-0 9) Compiex NumBers arbi (a,béR, = -4) = a-bi «tal = vate b tet = (asa) + E(B +b) + ys e * (ap- a2) + i (by be) + 2a, ~ (ayag- bbz) + tay by + a,b.) 2s 21a Veal? 44) COUNTING PRINCIPLES Addition Principle Tf A and B ave disjoint, IA UB = IAl + [BI Multiplication Principle Tf a task can be done in mm ways and then another in mn ways, Total ways = mixin Pigeonhole Principle Tf met objects in m boxes, at least one box has 2 objects POWER PRACTICE 5) EXPONENTS. + aM at = amen a En EM - ged) em = am + (ab)" = a” bY ay" a Fy (2) ares (b #0) + a = 4 (a #0) -n a 410) Mararces + (AB) = DD Au Bay pert + (ATT = A + (A+ BT = AT + BT + (AB)T = BT AT + det (AB) = det (A) - det (B) + det (A7) = det (A) b for he (SP), aetcay = ad be 15) ImPoRTANT CONSTANTS nm = 3.141592653589793 e = 2, 718281828459045 V2 = 4. 414213562373095 V3 = 4.732050807568877 In2 = 0. 693147480559945 InfO = 2.302585092994046 logio 2 = 0. 301029995663984 | Memorize key values ! on ‘ss — the KEY to SUCCESS! (©) Page 18 / 20 6) Factortas & nCr sont = n (nnd) (n-2) ee 224 elke a snl i nl! ri(ner)! one ew n€air 41) Sequences & Serres Arithmotic series sum sie) 2 Le 2eucene Sum of squares 2 Sum of cubes iat, sate: |f ia Nagar 9 hw te ated) 6 (net) ii 2 Geometric series sum Laer aa + oe eo (rw 4) 46) Userut Ipentitzes + (at bee) = oF + bh ect + (ab + be + ca) + (a-b)? + (b- ec)? + (e- a)? = Qa + B+ c? - ob - be ~ ca) soe athe a = Geko? 3 - AM = GM > HM }r abre + (ae byt < 2¢e% +b) } scout) * ComMPETITIVE PROGRAMMING, MatHEmaTics HANDBOOK 4) Numper THEORY ook for + Duisibility, GCD, LCM + Primes, fackors, remainders + Modular arithmatic (mod m) + Euler, Fermat, CRT Parity, remainders, Example + Count rember divisible by le YO Stee Seibel)” (pee ee Uhink “tools! ie ©) Crean aac = 9) 11) PoLynomzats & EQuaTzoNns (Factor smart.) © Find rook + Remainder when P(x) +(x-a) Nasa 3 roll rook ged, lem, mod, divisor, prime = > remoinder, congruence, mod inverse <9 Number Theory ways, count, permutations, combinakions > arrange, choose, distribute —? ie + 19. PROBLEM RECOGNITION GUIDE * How bo quickly idenkifiy which mathematical area / tool to use in a problem 2) ComBINATORICS Look for + Counk ways / arrangements / selections + Tnelusion= Exclusion + Pigeonhole Principle Ties + Ts order important? + Are. there restrictions / overlaps ? + Break inte cases if needed. Example wtp te fem tame (Ena + Senge with rateictims f (cau pga feange o™o) 2) MaTHEmaTIcAL OPTIMIZATION Look for + Max / Min problems + Constraints (S, @, =) + Resource allocation + Coat / profit optimination Think + Ts ik Linear? —» LP + Ts & nonclinear? —+ Derivatives + Use KKT for advanced problems Example + Maximise profit under budget / + Minimize cost / time ( + Fair distribution (ae 12) Loarc & Puzztes + Use truth / contradiction + Eliminate possibilities Example + Truth-taller / or punches + Einstein's hewse problem + Parity based problems 9 \_ } (Think logically, | C8) | t , t baa | 3) ALGEBRA ‘Look for + Equations , identities + Expressions to simplify + Systems of equations + Polynomioks, factorization a + Factor / expand + Substikuke to simplify Example + Solve equations FoF “ee ate fee = Max/Min of expressions | ©) SS ee + Win / leas / drow conditions + Tmpartial / scoring games Think + Who goins f T move? + Use Grundy / DP / Nim = Think optimal, nob greedy Example + Nim / Grundy. problems (Tink maa, + Stone removal games (win ahead! inc ae OO 43) Matrix & Linear ALGEBRA Quick CLUE TABLE (KEYworDS — ToPrc) Number Theory, equation, solve for x, ienkity —> Algebra sin, cos, tan, angle simplify, factor, polynomial Algebra sequence, sum, nth term, potter —* Combinatorics Lriangle, circle, area, distance > Geometry maximize, minimize, best, optimal —* Optimization. Combinatories, coordinate, slope, midpoint > Geometry probability, chance, expected ~ 4) GeomeTRY Look for + Points, lines, angles, circles + Distances, Think © Dray tages + Use formulas + Use vectors / coordinates if useful Example el + Find aren / parimatar | { + Shortest distonce, fabraai feos Z (wa nen LO) 9) PROBABILITY Leck for + Random events + Chances / Ukelihood + Expected welue + Independent / dependant events Tank © Difina comple. spice + Use formulas / rules + Break inte casas Example ao + Probability of ent (lela + Expected value 14 sccm? + Dice / coin problems KO) 44) Bart MANIPULATION Leste for + Powers of two + AND, OR, XOR, SHIFT + Set / unset bits + Parity / masks ‘Trike + Look et binary form + Use properties + Count / manipulate bits Example + Check of power of 2 + Count ant bite + XOR tricks > Trigonomatey Sequences & Series Probability 26000060 &| real Page 19 / 20 | 5) TRIGONOMETRY Look _for + Angles, sin, cos, tan + Periodic / eyelic patterns Think CR ey aaa u + Solve sin x = 0 + Max/Min of trig expe + Heights / distances 40) Discrete MATHEMATICS © Groph paths count Pa See diners: Teo arpa (Pett ~ See | + Set operations es GeNeraL STRATEGY Match with Ure right topic (1-14) Choose the best tool / formula. Solve small cases / example Verify and. optimize solubion two players, turns, win, lose > Game Theory motrix, determinant, ronk, system + Linear Algebra bits, xor, and, or, shift > Bit Manipulation logic, if, parity, pursle Sager rae