コード例 #1
0
 public void InverseFactorTest()
 {
     for (var i = 1; i < 1000; i++)
     {
         var powers = PrimeFactors.Factor(i);
         Assert.That(PrimeFactors.Value(powers), Is.EqualTo(i));
     }
 }
コード例 #2
0
        public void FactorTest()
        {
            var r32  = new[] { 5 };
            var r210 = new[] { 1, 1, 1, 1 };

            Assert.That(PrimeFactors.Factor(32), Is.EqualTo(r32));
            Assert.That(PrimeFactors.Factor(210), Is.EqualTo(r210));
        }
コード例 #3
0
        /// <summary>
        /// Generate an iterator over the proper divisors of the number passed in,
        /// other than the number itself.
        /// Iteration will proceed as for <see cref="Divisors(int[])"/>.
        /// </summary>
        /// <param name="value">Value whose divisors are desired</param>
        /// <returns>An enumerator over all proper divisors of the number.</returns>
        public static IEnumerable <int> ProperDivisors(int value)
        {
            var factors = PrimeFactors.Factor(value);

            foreach (var i in Divisors(factors))
            {
                if (i < value)
                {
                    yield return(i);
                }
            }
        }
コード例 #4
0
 /// <summary>
 /// Count the number of possible divisors of a number, including 1 and the number itself.
 /// </summary>
 /// <param name="value">The number to test.</param>
 /// <returns>the number of possible divisors of the original number.</returns>
 public static int CountDivisors(int value)
 {
     return(CountDivisors(PrimeFactors.Factor(value)));
 }
コード例 #5
0
 /// <summary>
 /// Get the perfection of a number.  A number whose proper divisors
 /// add up to the number is called "perfect".  If the sum is less then the
 /// number it is called "deficient".  Otherwise it is called "abundant".
 /// </summary>
 /// <param name="value">The number</param>
 /// <returns>-1 if deficient, 0 if perfect, 1 if abundant</returns>
 public static int Perfection(int value)
 {
     return(Perfection(PrimeFactors.Factor(value)));
 }
コード例 #6
0
 /// <summary>
 /// Generate an iterator over the divisors of the number passed in.
 /// Iteration will proceed as for <see cref="Divisors(int[])"/>.
 /// </summary>
 /// <param name="value">Value whose divisors are desired</param>
 /// <returns>An enumerator over all divisors of the number.</returns>
 public static IEnumerable <int> Divisors(int value)
 {
     return(Divisors(PrimeFactors.Factor(value)));
 }
コード例 #7
0
        public void InverseFactorValue(int value)
        {
            var powers = PrimeFactors.Factor(value);

            Assert.That(PrimeFactors.Value(powers), Is.EqualTo(value));
        }