Beispiel #1
0
        public void ExtendedEuclid()
        {
            for (int i = 1; i <= 100; i++)
            {
                for (int j = i + 1; j <= 100; j++)
                {
                    Test(i, j);
                }
            }

            void Test(long a, long b)
            {
                var g = Primes.Gcd(a, b);

                a        /= g; b /= g;
                var(x, y) = Primes.ExtendedEuclid(a, b);
                Assert.IsTrue(Math.Abs(x) <= b);
                Assert.IsTrue(Math.Abs(y) <= a);
                Assert.AreEqual(1, a * x + b * y);
            }
        }