1 数字的算法
1.1 基本算数
1.1.1 加法
- 加法复杂度 O(n)
1.1.2 乘法和除法
- (复杂度 O(n2) )
funtion 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,⌊ y/2 ⌋)
if y is even:
return 2z
else
return x+2z
function divide(x,y)
Input:Two n-bit integers x and y, where y ≥ 1
Output:Their quotinent and remainder of x divided by y
if x=0: return (q,r)=(0,0)
(q,r)=divide(⌊ x/2 ⌋,y)
q=2q,r=2r
if x is odd: r=r+1
if r≥y: r=r-y,q=q+1
return (q,r)
1.2 模运算
- 求