var k1=1,k2=1,find1;     if(a==c || b==d){k1=1;k2=-1}else if(gcd(a,c)>1){k1=c/gcd(a,c);k2=-a/gcd(a,c)}else if(gcd(b,d)>1){k1=d/gcd(b,d);k2=-b/gcd(b,d)}else if(a==1){k1=c;k2=-1}else if(b==1){k1=d;k2=-1}else if(c==1){k1=1;k2=-a}else if(d==1){k1=1;k2=-b}else {k1=c;k2=-a};if(k1==-1){k1=1;k2=-k2;};if(k2==-1){k1=-k1;k2=1};find1=(k1*a+k2*c==0?1:0);document.writeln("First eliminate one variable.<br>",(k1!=1?"Multiply the top equation by "+showterms([[k1,1]]):""),(k2!=1?(k1!=1?"; m":"M")+"ultiply the bottom equation by "+showterms([[k2,1]]):""),   (k1!=1||k2!=1?":<br>":""),   "<blockquote>",    showterms([[k1*a,v[0]],[k1*b,v[1]]," = ",[k1*(a*x+b*y),1]]),"<br>",    showterms([[k2*c,v[0]],[k2*d,v[1]]," = ",[k2*(c*x+d*y),1]]),"</blockquote>","Add these equations:<blockquote>",    (find1==0&&k1*a+k2*c==1 ||find1==1&&k1*b+k2*d==1      ?"<span class=u>&nbsp;":""),    showterms([[k1*a+k2*c,v[0]],[k1*b+k2*d,v[1]]," = ",[k1*(a*x+b*y)+k2*(c*x+d*y),1]]),    (find1==0&&k1*a+k2*c==1||find1==1&&k1*b+k2*d==1?"&nbsp;</span>":""),        (find1==0?( k1*a+k2*c!=1?"<br>"+iffch+"<span class=u>&nbsp;"+showterms([[1,v[0]]," = ",[x,1]])+"&nbsp;</span>":"")             :( k1*b+k2*d!=1?"<br>"+iffch+"<span class=u>&nbsp;"+showterms([[1,v[1]]," = ",[y,1]])+"&nbsp;</span>":"")), "</blockquote>Substitute this value in the first (original) equation:<blockquote>",    (find1==0&&a*x!=0 || find1==1&& b*y!=0     ?showterms([[(find1==0?a*x:a),find1==0?1:v[0]],               [(find1==1?b*y:b),find1==1?1:v[1]]," = ",[a*x+b*y,1]])+"<br>"+iffch     :""),    (find1==0&&b==1||find1==1&&a==1?"<span class=u>&nbsp;":""),    (find1==0?showterms([[b,v[1]]," = ",[b*y,1]]):showterms([[a,v[0]]," = ",[a*x,1]])),               (find1==0&&b==1||find1==1&&a==1?"&nbsp;</span>":""),"<br>",    (find1==0&&b!=1||find1==1&&a!=1    ?iffch+"<span class=u>&nbsp;"+showterms([[1,v[1-find1]]," = ",[find1==0?y:x,1]])+"&nbsp;</span>"    :""),    "</blockquote><br>"    );