Using a method from Paul S. Wang, it is possible to recover
from
and
using the Euclidean algorithm, as follows.[1][2]
One puts
and
. One then repeats the following steps until the first component of w becomes
. Put
, put z = v − qw. The new v and w are then obtained by putting v = w and w = z.
Then with w such that
, one makes the second component positive by putting w = −w if
. If
and
, then the fraction
exists and
and
, else no such fraction exists.