Java:
public class ExtendedEuclid {
static int[] gcd(int p, int q) {
if (q == 0)
return new int[] { p, 1, 0 };
int[] vals = gcd(q, p % q);
int d = vals[0];
int a = vals[2];
int b = vals[1] - (p / q) * vals[2];
return new int[] { d, a, b };
}
public static void main(String[] args) {
int p = Integer.parseInt(args[0]);
int q = Integer.parseInt(args[1]);
int vals[] = gcd(p, q);
System.out.println("gcd(" + p + ", " + q + ") = " + vals[0]);
System.out.println(vals[1] + "(" + p + ") + " + vals[2] + "(" + q + ") = " + vals[0]);
}
}
Dieser Code berechnet den ggT von(p,q), sowie s und t.
Also: p*s+t*q=ggT(p,q)
Jedoch kann es z.B. "5682864303300955799" (,also sagen wir mal als p) und eine zweite gleich große Zahl nicht verarbeiten.
Ich habe es natürlich auch schon mit "double" versucht.
Aber es wird ausgegeben, dass die Eingabezahl zu groß sei.
Was mache falsch, kann mich jemand korrigieren?
Zuletzt bearbeitet: