Beispiel #1
0
        BigNum K(BigNum z)
        {
            BigNum        ans  = new BigNum(0);
            List <double> temp = new List <double>();

            z.GetValue().ToList().ForEach(x => ans += (x - '0'));
            return(ans);
        }
Beispiel #2
0
        BigNum J(BigNum z)
        {
            BigNum ans = new BigNum(1);

            for (BigNum i = new BigNum(1); i < z + 1; i += 1)
            {
                ans *= new BigNum(i.GetValue());
                FenJ(i);
            }
            return(ans);
        }
Beispiel #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            ZL = new List <int>();
            BigNum A  = new BigNum(textBox1.Text);
            BigNum AJ = J(A);
            BigNum AK = K(AJ);

            textBox2.Text = AJ.GetValue();
            textBox3.Text = AK.GetValue();
            textBox4.Text = ZL.Count.ToString();
        }
Beispiel #4
0
        public static BigNum operator -(BigNum a, BigNum b)
        {
            BigNum c = new BigNum(0);

            if (a < b)
            {
                BigNum temp;
                temp = new BigNum(a.GetValue());
                a    = new BigNum(b.GetValue());
                b    = new BigNum(temp.GetValue());
                return(new BigNum(-1));
            }
            a.Value.Reverse();
            b.Value.Reverse();
            while (a.Value.Count < b.Value.Count)
            {
                a.Value.Add(0);
            }
            while (a.Value.Count > b.Value.Count)
            {
                b.Value.Add(0);
            }
            while (c.Value.Count < a.Value.Count)
            {
                c.Value.Add(0);
            }
            double carry = 0;

            for (int i = 0; i < a.Value.Count; i++)
            {
                c.Value.Add(0);
                double temp = 0;
                temp       = a.Value[i] - carry - b.Value[i]; //a-b-c
                carry      = (temp < 0 ? 1 : 0);              //<0就借位
                c.Value[i] = temp;
            }
            c.Value.Reverse();
            BigNum ans  = new BigNum();
            bool   flag = false;

            foreach (var item in c.Value)
            {
                if (item != 0)
                {
                    flag = true;
                }
                if (flag)
                {
                    ans.Value.Add(item);
                }
            }
            return(ans);
        }
Beispiel #5
0
        void FenJ(BigNum z)
        {
            int a = int.Parse(z.GetValue().ToString());

            if (a == 2)
            {
                ZL.Add(2);
                return;
            }
            if (a < 2)
            {
                return;
            }

            if (a == 2)
            {
                ZL.Add(2);
            }
            int count = 2;

            while (a != 1)
            {
                while (true)
                {
                    if (a % count == 0)
                    {
                        ZL.Add(count);
                        a /= count;
                    }
                    else
                    {
                        break;
                    }
                }
                count++;
            }
        }