Download presentation
Presentation is loading. Please wait.
Published bySuharto Sanjaya Modified over 6 years ago
1
Discrete Math for CS CMPSC 360 LECTURE 12 Last time: Stable matching
Modular arithmetic Today: Exponentiation Multiplicative Inverses Extended Euclidβs algorithm CMPSC 360 11/29/2018
2
Modular exponentiation
Naive algorithm to compute π₯ π¦ mod π. mod-exp-naive(π,π,π) Input: integer π, natural number π, positive integer π. if π=π then return 1 else π= mod-exp-naive(π,πβπ,π) return (πβ
π mod π) 11/29/2018
3
I-clicker problem (frequency: BC)
If π¦ has π bits, how many multiplications mod π are performed when we compute π₯ π¦ mod π by the naive algorithm? Find the largest correct bound: At least βπ. At least π. At least 2π. At least π 2 . At least 2 πβ1 . 11/29/2018
4
Modular exponentiation
Uses repeated squaring to compute π₯ π¦ mod π. mod-exp(π,π,π) Input: integer π, natural number π, positive integer π. if π=π then return 1 else π= mod-exp(π,π div π,π) if π mod 2 =π then return (πβ
π mod π) else return (πβ
πβ
π mod π) 11/29/2018
5
I-clicker problem (frequency: BC)
If π¦ has π bits, how many multiplications mod π are performed when we compute π₯ π¦ mod π by repeated squaring? Find the smallest correct bound: At most βπ. At most π. At most 2π. At most π 2 . At most 2 πβ1 . 11/29/2018
6
Definitions If π₯β
π¦β‘1 (mod π) then π¦ is a multiplicative inverse of π₯ modulo π. The greatest common divisor of natural numbers π₯ and π¦, denoted gcd(π₯,π¦), is the largest natural number that divides both. If gcd(π₯,π¦)=1 then π₯ and π¦ are relatively prime (also called coprime). 11/29/2018
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.