chg: changed extgcd (because of extegcd(x,x) ovver Q)