1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117:
| uses fgint; procedure polyggt; const maxgrad = 8; var a,b,q,r:array[0..maxgrad] of TFGInt; ff,fa,fb,rest,f1,f2,null: TFGint; n,m,i:integer; ende,abbrucha,abbruchb:boolean; begin numberToFGInt(0,null);
abbrucha:=true; abbruchb:=true; for i:=0 to maxgrad do abbrucha:=abbrucha and (FGIntCompareAbs(a[i],null)=eq); for i:=0 to maxgrad do abbruchb:=abbruchb and (FGIntCompareAbs(b[i],null)=eq); if abbrucha or abbruchb then begin for i:=0 to maxgrad do FGIntDestroy(a[i]); for i:=0 to maxgrad do FGIntDestroy(b[i]); FGIntDestroy(null); exit; end;
repeat for i:=0 to maxgrad do numberToFGInt(0,q[i]); for i:=0 to maxgrad do numberToFGInt(0,r[i]); n:=maxgrad; while (FGIntCompareAbs(a[n],null)=eq) and (n>0) do dec(n); m:=maxgrad; while (FGIntCompareAbs(b[m],null)=eq) and (m>0) do dec(m);
FGIntMod(a[n],b[m],rest);
if FGIntCompareAbs(rest,null)<>eq then begin FGIntGCD(a[n],b[m],ff); FGIntDiv(a[n],ff,f1); FGIntMul(b[m],f1,ff); FGIntDiv(ff,a[n],fa); FGIntDiv(ff,b[m],fb);
for i:=0 to n do begin FGINtmul(fa,a[i],f1); a[i]:=f1 end; for i:=0 to m do begin FGINtmul(fb,b[i],f1); b[i]:=f1 end; end;
if (m>0) then begin while (n>=m) do begin fgintdiv(a[n],b[m],q[n-m]); for i:=0 to m do begin fgintmul(q[n-m],b[m-i],f1); fgintsub(a[n-i],f1,f2); a[n-i]:=f2; end; dec(n); end; for i:=0 to maxgrad do r[i]:=a[i]; end;
ende:=true; for i:=0 to maxgrad do if FGIntCompareAbs(r[i],null)<>eq then ende:=false;
a:=b; b:=r; until ende;
f1:=a[0]; for i:=1 to maxgrad do begin FGIntGCD(a[i],f1,f2); f1:=f2; end; for i:=0 to maxgrad do begin FGIntdiv(a[i],f1,f2); a[i]:=f2; end;
for i:=0 to maxgrad do FGIntDestroy(a[i]); for i:=0 to maxgrad do FGIntDestroy(b[i]); for i:=0 to maxgrad do FGIntDestroy(q[i]); for i:=0 to maxgrad do FGIntDestroy(r[i]); FGIntDestroy(rest); FGIntDestroy(ff); FGIntDestroy(fa); FGIntDestroy(fb); FGIntDestroy(f1); FGIntDestroy(f2); FGIntDestroy(null); end; |