Example #1
0
        /// <summary>第一次用开方尝试</summary>
        private static List <int> FirstTry(List <int> result, List <int> div)
        {
            int tryDiv = BigNumber.Max / 2;
            int low    = 1;
            int top    = BigNumber.Max - 1;

            //第一位数是1

            //第一用平方试商
            while (true)
            {
                if (BigCalculate.CompareList(new List <int>()
                {
                    1
                }, div) == 0)
                {
                    div = BigCalculate.IntMinus(div, new List <int>()
                    {
                        1
                    });
                    result.Add(1);
                    break;
                }
                //连9都小了,那么就是9
                if (BigCalculate.CompareList(BigCalculate.Multiply(BigNumber.Max - 1, BigNumber.Max - 1), div) == -1)
                {
                    div = BigCalculate.IntMinus(div, BigCalculate.Multiply(BigNumber.Max - 1, BigNumber.Max - 1));
                    result.Add(BigNumber.Max - 1);
                    break;
                }
                int c = BigCalculate.CompareList(BigCalculate.Multiply(tryDiv, tryDiv), div);
                //商大了
                if (c == -1)
                {
                    low    = tryDiv;
                    tryDiv = (low + top) / 2;
                }
                else if (c == 1)     //商小了
                {
                    top    = tryDiv;
                    tryDiv = (low + top) / 2;
                }
                else     //刚好相等
                {
                    div.Clear();
                    result.Add(tryDiv);
                    break;
                }

                if (low + 1 == top)
                {
                    div = BigCalculate.IntMinus(div, BigCalculate.Multiply(low, low));
                    result.Add(low);
                    break;
                }
            }
            return(div);
        }
Example #2
0
        /// <summary>计算x(x+20*result)的值</summary>
        static List <int> CalDiv(int x, List <int> result)
        {
            List <int> result20 = BigCalculate.Multiply(new List <int>()
            {
                BigNumber.Max * 2
            }, result);
            List <int> add = BigCalculate.IntAdd(new List <int>()
            {
                x
            }, result20, 0);
            List <int> r = BigCalculate.Multiply(new List <int>()
            {
                x
            }, add);

            return(r);
        }
Example #3
0
 public static BigNumber operator *(BigNumber a, BigNumber b)
 {
     return(BigCalculate.Multiply(a, b));
 }