The Accelerated Integer GCD Algorithm

Download Report

Transcript The Accelerated Integer GCD Algorithm

The Accelerated Integer GCD
Algorithm
KENNETH WEBER
Kent State University
ACM Transactions on Mathematical Software
張圻毓
1
Outline




Main algorithm
Dmod operation
General ReducedRatMod algorithm
Example
2
Main algorithm













Input: uo, vo >0, with lβ (uo) ≧lβ (vo) and gcd(uo,β)=gcd(vo,β) = 1
Output: gcd(uo, vo)
u=u0 , v=v0
while v ≠ 0 do
if lβ (u) - lβ (v) > s(v) then
u = dmod(u, v,β)
else
(n, d) = ReducedRatMod(u, v, β2t(v))
u = |nv – dul|/ β2t(v)
RemoveFactors(u,β)
swap(u,v)
x = gcd(dmod(vo, u, β), u)
return gcd(dmod(uo, x, β), x)
3
Dmod operation

The dmod (“digit modulus”) operation is
defined as
4
Dmod operation









Input: uo, vo,β >0, with gcd(vo,β) = 1
Output: |u0-(u0/v0 mod βlβ(u0)-lβ(v0)+1)v0|/βlβ(u0)-lβ(v0)+1
u = uo
while lβ(u) ≧ lβ (v0) + W do
if u ≠ 0 (mod βw) then u = |u – (u/v0 mod βw)vo|
u = u/βw
d = lβ(u) - lβ (v0)
if u ≠ 0 (modβ d+1) then u = |u – (u/v0 mod βd+1)vo|
return u/βd+1
5
General ReducedRatMod algorithm









Input: .x, y>0, m > 1 with gcd(x,m)=gcd(y, m)= 1
Output: (n, d) such that 0 < n , |d|< √m and ny=xd (mod
m)
c = x/y mod m
f1=(n1,d1)=(m,0)
f2=(n2,d2)=(c,1)
while n2≧ √m
f1= f1-└n1/n2┘f2
swap(f1,f2)
return f2
6
Example






u=243 v=231 m=64
C=243/231 mod 64
f1=(n1,d1)=(m,0)=(64,0)
f2=(n2,d2)=(c,1)=(21,1)
f1=(21,1) f2=(1,-3)
u =|1*231-(-3)*243| /64 = 15
7
Example







u=231 v=15 m=64
C=231/15 mod 64
f1=(n1,d1)=(m,0)=(64,0)
f2=(n2,d2)=(c,1)=(23,1)
f1=(23,1) f2=(18,-2)
f1=(18,-2) f2=(5,3)
u =|5*15-3*231| /64 = 12
8
Example99






u=15 v=12/4=3 m=64
C=15/3 mod 64
f1=(n1,d1)=(m,0)=(64,0)
f2=(n2,d2)=(c,1)=(59,1)
f1=(59,1) f2=(5,-1)
u =|5*12+1*15| /64 = < 64
9