Modular Arithmetic and Primality

Modular Arithmetic and Primality Modular Arithmetic and Primality

axon.cs.byu.edu
from axon.cs.byu.edu More from this publisher
01.01.2015 Views

function multiply(x,y) Input: Two n-bit integers x and y, where y ≥ 0 Output: Their product if y = 0: return 0 z = multiply(x, floor(y/2)) if y is even: return 2z else: return x+2z Is it better than classical multiplication CS 312 - Complexity Examples - Arithmetic and RSA 14

function multiply(x,y) Input: Two n-bit integers x and y, where y ≥ 0 Output: Their product if y = 0: return 0 z = multiply(x, floor(y/2)) if y is even: return 2z else: return x+2z Is it better than classical multiplication Don’t need to know all the times tables, just need to double and half, which could be an advantage - especially easy in binary Complexity – n function calls where n is the length in bits of the binary y (n = log 2 y) – Each call has how many n-bit adds – Thus big-OH complexity is CS 312 - Complexity Examples - Arithmetic and RSA 15

function multiply(x,y)<br />

Input: Two n-bit integers x <strong>and</strong> y, where y ≥ 0<br />

Output: Their product<br />

if y = 0: return 0<br />

z = multiply(x, floor(y/2))<br />

if y is even: return 2z<br />

else: return x+2z<br />

Is it better than classical multiplication<br />

CS 312 - Complexity Examples - <strong>Arithmetic</strong> <strong>and</strong> RSA 14

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!