# hw9sol - Computer Science 340 Reasoning about Computation...

• Homework Help
• PresidentHackerCaribou10582
• 2
• 100% (6) 6 out of 6 people found this document helpful

This preview shows pages 1–2. Sign up to view the full content.

Computer Science 340 Reasoning about Computation Homework 9 Due at the beginning of class on Wednesday, November 28, 2007 Problem 1 Consider the following computational problem: Given N, a, b, x, y , where N 1 is prime, a, b, x, y are integers between 1 and N - 1, compute a x b y (mod N ). 1. Describe an algorithm that takes at most 4 k + C multiplications, where k = log N and C is a positive constant. 2. Design an algorithm that uses at most 2 k + C multiplications, for some constant C . Solution sketch: The naive algorithm computes a x (mod N ) then b y (mod N ) and then multiplies them modulo N . This takes roughly 4 k multiplications, using repeated exponentiation. To halve that number, let x k - 1 · · · x 1 x 0 and y k - 1 · · · y 1 y 0 be the binary representations of x and y . Set c = ab (mod N ) and z = 1. Then repeat for i = k - 1 down to 0: if ( x i , y i ) = (1 , 1) then set z to z 2 .c (mod N ); if ( x i , y i ) = (1 , 0) then set z to z 2 .a (mod N ); if ( x i , y i ) = (0 , 1) then set z to z 2 .b (mod N ); if ( x i , y i ) = (0 , 0) then set z to z 2 (mod N ). Problem 2 A common form of Fermat’s theorem is: a p = a (mod p ), for any prime p and integer a . Prove this by induction on a . (Hint: prove that ( a + b ) p = a p + b p modulo p ). Solution sketch: 1. ( p

This preview has intentionally blurred sections. Sign up to view the full version.

This is the end of the preview. Sign up to access the rest of the document.
• Fall '07
• CharikarandChazelle
• Exponentiation, Natural number, Prime number, Solution sketch

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern