public static ExtendedEuclideanResult ExtendedEuclide(int a, int b) { int x = 1; int d = a; int v1 = 0; int v3 = b; while (v3 > 0) { int q0 = d / v3; int q1 = d % v3; int tmp = v1 * q0; int tn = x - tmp; x = v1; v1 = tn; d = v3; v3 = q1; } int tmp2 = x * (a); tmp2 = d - (tmp2); int res = tmp2 / (b); var result = new ExtendedEuclideanResult() { X = x, Y = res, Gcd = d }; return(result); }
/// <summary> /// u1 * a + u2 * b = u3 /// </summary> /// <param name="a">Число a</param> /// <param name="b">Модуль числа</param> private static ExtendedEuclideanResult ExtendedEuclide(int a, int b) { int u1 = 1; int u3 = a; int v1 = 0; int v3 = b; while (v3 > 0) { int q0 = u3 / v3; int q1 = u3 % v3; int tmp = v1 * q0; int tn = u1 - tmp; u1 = v1; v1 = tn; u3 = v3; v3 = q1; } int tmp2 = u1 * (a); tmp2 = u3 - (tmp2); int res = tmp2 / (b); ExtendedEuclideanResult result = new ExtendedEuclideanResult() { u1 = u1, u2 = res, gcd = u3 }; return(result); }
public static ExtendedEuclideanResult ExtendedEuclide(BigInteger a, BigInteger b) { BigInteger x = 1; BigInteger d = a; BigInteger v1 = 0; BigInteger v3 = b; while (v3 > 0) { BigInteger q0 = d / v3; BigInteger q1 = d % v3; BigInteger tmp = v1 * q0; BigInteger tn = x - tmp; x = v1; v1 = tn; d = v3; v3 = q1; } BigInteger tmp2 = x * (a); tmp2 = d - (tmp2); BigInteger res = tmp2 / (b); ExtendedEuclideanResult result = new ExtendedEuclideanResult() { x = x, y = res, gcd = d }; return result; }
private static ExtendedEuclideanResult ExtendedEuclide(long a, long b) { long u1 = 1; long u3 = a; long v1 = 0; long v3 = b; while (v3 > 0) { long q0 = u3 / v3; long q1 = u3 % v3; long tmp = v1 * q0; long tn = u1 - tmp; u1 = v1; v1 = tn; u3 = v3; v3 = q1; } long tmp2 = u1 * (a); tmp2 = u3 - (tmp2); long res = tmp2 / (b); ExtendedEuclideanResult result = new ExtendedEuclideanResult() { u1 = u1, u2 = res, gcd = u3 }; return(result); }
public static ExtendedEuclideanResult ExtendedEuclide(BigInteger a, BigInteger b) { BigInteger x = 1; BigInteger d = a; BigInteger v1 = 0; BigInteger v3 = b; while (v3 > 0) { BigInteger q0 = d / v3; BigInteger q1 = d % v3; BigInteger tmp = v1 * q0; BigInteger tn = x - tmp; x = v1; v1 = tn; d = v3; v3 = q1; } BigInteger tmp2 = x * (a); tmp2 = d - (tmp2); BigInteger res = tmp2 / (b); ExtendedEuclideanResult result = new ExtendedEuclideanResult() { x = x, y = res, gcd = d }; return(result); }
private static ExtendedEuclideanResult ExtendedEuclide(int a, int b) { int u1 = 1; int u3 = a; int v1 = 0; int v3 = b; while (v3 > 0) { int q0 = u3 / v3; int q1 = u3 % v3; int tmp = v1 * q0; int tn = u1 - tmp; u1 = v1; v1 = tn; u3 = v3; v3 = q1; } int tmp2 = u1 * (a); tmp2 = u3 - (tmp2); int res = tmp2 / (b); ExtendedEuclideanResult result = new ExtendedEuclideanResult() { u1 = u1, u2 = res, gcd = u3 }; return result; }
/// <summary> /// u1 * a + u2 * b = u3 /// </summary> private ExtendedEuclideanResult ExtendedEuclide(BigInteger a, BigInteger b) { BigInteger u1 = 1; BigInteger u3 = a; BigInteger v1 = 0; BigInteger v3 = b; while (v3 > 0) { BigInteger q0 = u3/v3; BigInteger q1 = u3%v3; BigInteger tmp = v1*q0; BigInteger tn = u1 - tmp; u1 = v1; v1 = tn; u3 = v3; v3 = q1; } BigInteger tmp2 = u1 * (a); tmp2 = u3 - (tmp2); BigInteger res = tmp2 / (b); var result = new ExtendedEuclideanResult() { U1 = u1, U2 = res, Gcd = u3 }; return result; }