예제 #1
0
        public void Primality_Test()
        {
            var natural1 = new Natural(Int32.MaxValue - 1);
            var natural2 = new Natural(678);
            var hardphi  = new Natural(667);
            var actual   = natural1.PrimeFactorize();

            Console.WriteLine("\nFactors of {0} are: ", natural1);
            foreach (var element in actual)
            {
                Console.Write(element + " ");
            }
            var actual2 = natural2.PrimeFactorize();

            Console.WriteLine("\nFactors of {0} are: ", natural2);
            foreach (var element in actual2)
            {
                Console.Write(element + " ");
            }

            var distinctlist = natural1.DistinctPrimeFactors();

            Console.WriteLine("\nDistinct Factors of {0} are: ", natural1);
            foreach (var element in distinctlist)
            {
                Console.Write(element + " ");
            }
            var distinctlist2 = hardphi.DistinctPrimeFactors();

            Console.WriteLine("\nDistinct Factors of {0} are: ", hardphi);
            foreach (var element in distinctlist2)
            {
                Console.Write(element + " ");
            }
            int expected = 616;
            var phi      = hardphi.CountRelativelyPrimes();

            Console.Write("\nφPhi of {0} is: " + phi, hardphi);
            Assert.AreEqual(expected, phi);
        }