예제 #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);
            }
        }
예제 #2
0
        public void Gcd()
        {
            for (int i = 1; i <= 100; i++)
            {
                for (int j = 1; j <= 200; j++)
                {
                    Test(i, j);
                }
            }

            void Test(int x, int y)
            {
                var actual = Primes.Gcd(x, y);

                Assert.IsTrue(x % actual == 0 && y % actual == 0);
                for (int i = Math.Min(x, y); i > actual; i--)
                {
                    Assert.IsFalse(x % i == 0 && y % i == 0);
                }
            }
        }