コード例 #1
0
        void parabolic(BigInteger a, BigInteger b, BigInteger c, BigInteger d, BigInteger e, BigInteger f)
        {
            var g = BigIntegerExt.Gcd(a, c);

            c = (c / g).Abs().Sqrt();
            if (b.Sign > 0 == a.Sign < 0)
            {
                c = -c;
            }
            a = (a / g).Abs().Sqrt();

            var m = c * d - a * e;

            if (m.IsZero)
            {
                var u = MathExt2.DeriveQuadratic(a * g, d, a * f, true);
                if (u.Length > 0)
                {
                    linearWithGcd(a, c, -u[0]);
                    if (u.Length > 1 && u[0] != u[1])
                    {
                        linearWithGcd(a, c, -u[1]);
                    }
                }
            }
            else
            {
                parabolic2(a, -c, m, a * g, d, a * f);
            }
        }
コード例 #2
0
        void elliptical(BigInteger a, BigInteger b, BigInteger c, BigInteger d, BigInteger e, BigInteger f)
        {
            var m = 4 * a;
            var i = m * c - b * b;
            var j = m * e - 2 * b * d;
            var k = m * f - d * d;
            var n = MathExt2.DeriveQuadratic(i, j, k, false);

            if (n.Length == 0)
            {
                return;
            }
            m = 2 * a;
            for (var u = n[0]; u <= n[1]; u += BigInteger.One)
            {
                var v = -(i * u * u + j * u + k);
                var w = v.Sqrt();
                if (w * w == v)
                {
                    var s = d + (b * u);
                    addStaticSolution((Rational)(w - s) / m, u);
                    addStaticSolution((Rational)(-w - s) / m, u);
                }
            }
        }
コード例 #3
0
        public static void DeriveQuadratic()
        {
            //this example shows how to find integer solution for aXX + bX + c = 0

            //example -2XX + X + 15
            //use MathExt2.DeriveQuadratic(a,b,c) to derive quadratic formula
            BigInteger[] xs = MathExt2.DeriveQuadratic(-2, 1, 15);

            //Show results
            Console.WriteLine(xs[0]);
            Console.WriteLine();

            //Recheck
            Console.WriteLine("-2*{0}*{0} + {0} + 15 = {1}", xs[0], -2 * xs[0] * xs[0] + xs[0] + 15);
        }