Finding a and d given two terms