Example #1
0
        public void Combination()
        {
            var factor = new StaticModIntFactor <Mod1000000007>(10);

            for (int i = 0; i <= 10; i++)
            {
                for (int j = 0; j <= 10; j++)
                {
                    factor.Combination(i, j).Value.Should().Be((int)MathLibEx.Combination(i, j));
                }
            }
            factor.Invoking(factor => factor.Combination(11, 0)).Should().Throw <Exception>();
        }
 public void DivisorLong()
 {
     MathLibEx.Divisor(1L).Should().Equal(new long[] { 1 });
     MathLibEx.Divisor(128100283921).Should().Equal(new long[] {
         1,
         71,
         5041,
         357911,
         25411681,
         1804229351,
         128100283921
     });
     MathLibEx.Divisor(132147483703).Should().Equal(new long[] { 1, 132147483703 });
     MathLibEx.Divisor(963761198400).Should().HaveCount(6720); //高度合成数
 }
 public void Combination()
 {
     for (int i = 0; i <= 10; i++)
     {
         for (int j = 0; j <= i; j++)
         {
             long n = 1, d = 1;
             for (int k = 0; k < j; k++)
             {
                 n *= i - k;
                 d *= k + 1;
             }
             MathLibEx.Combination(i, j).Should().Be(n / d);
         }
     }
 }
        public void CombinationTable()
        {
            var c = MathLibEx.CombinationTable <long, LongOperator>(10);

            for (int i = 0; i <= 10; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    long n = 1, d = 1;
                    for (int k = 0; k < j; k++)
                    {
                        n *= i - k;
                        d *= k + 1;
                    }
                    c[i][j].Should().Be(n / d);
                }
            }
        }
        public void DivisorInt()
        {
            MathLibEx.Divisor(1).Should().Equal(new int[] { 1 });
            MathLibEx.Divisor(1000000007).Should().Equal(new int[] { 1, 1000000007 });
            MathLibEx.Divisor(49).Should().Equal(new int[] { 1, 7, 49 });
            MathLibEx.Divisor(720).Should().Equal(new int[] {
                1, 2, 3, 4, 5, 6, 8, 9, 10,
                12, 15, 16, 18, 20, 24, 30,
                36, 40, 45, 48, 60, 72, 80,
                90, 120, 144, 180, 240, 360, 720
            });
            MathLibEx.Divisor(6480).Should()
            .StartWith(new int[] { 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 27, 30, 36, 40, 45, 48, 54, 60, 72, 80, 81 })
            .And
            .EndWith(new int[] { 1620, 2160, 3240, 6480 })
            .And
            .HaveCount(50);

            MathLibEx.Divisor(2095133040).Should().HaveCount(1600); //高度合成数
        }
 public void LcmIntParamsTest(int[] nums, int expected)
 {
     MathLibEx.Lcm(nums).Should().Be(expected);
 }
 public void LcmIntTest(int num1, int num2, int expected)
 {
     MathLibEx.Lcm(num1, num2).Should().Be(expected);
 }
 public void GcdLongParamsTest(long[] nums, long expected)
 {
     MathLibEx.Gcd(nums).Should().Be(expected);
 }
 public void GcdLongTest(long num1, long num2, long expected)
 {
     MathLibEx.Gcd(num1, num2).Should().Be(expected);
 }
 public void GcdIntParamsTest(int[] nums, int expected)
 {
     MathLibEx.Gcd(nums).Should().Be(expected);
 }
 public void GcdIntTest(int num1, int num2, int expected)
 {
     MathLibEx.Gcd(num1, num2).Should().Be(expected);
 }
 public void LcmLongTest(long num1, long num2, long expected)
 {
     MathLibEx.Lcm(num1, num2).Should().Be(expected);
 }