rseuclid := proc(t, f, g, z, p, a)
    local q, r, rm1, rp1, um1, u, up1, vm1, v, vp1, i;
    rm1 := sort(Expand(f) mod 2);
    r := sort(Expand(g) mod 2);
    um1 := 1;
    u := 0;
    vm1 := 0;
    v := 1;
    while degree(r,z) >= t do
        rp1 := Rem(rm1, r, z, 'q') mod 2;
        rp1 := rscoeff(rp1, z, p, a);
        q := rscoeff(q, z, p, a);
        vp1 := expand(vm1 - v*q) mod 2;
        vm1 := v;
        v := sort(vp1, z);
        v := rscoeff(v, z, p, a);
        up1 := expand(um1 - u*q) mod 2;
        um1 := u;
        u := sort(up1);
        u := rscoeff(u, z, p, a);
        rm1 := r;
        r := sort(rp1, z);
        print(`Q = `, q, `   R = `, r, 
              `   V = `, v, `   U = `, u);
    od;
    print();
    RETURN(q, r, v, u):
end: