Esempio n. 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));
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Generate an iterator over the divisors of the number whose prime
        /// factorization has been passed in, other than the number itself.
        /// Iteration will proceed as for <see cref="Divisors(int[])"/>.
        /// </summary>
        /// <param name="factors">Prime factors of the value whose divisors are desired</param>
        /// <returns>An enumerator over all proper divisors of the number.</returns>
        public static IEnumerable <int> ProperDivisors(int[] factors)
        {
            var value = PrimeFactors.Value(factors);

            foreach (var i in Divisors(factors))
            {
                if (i < value)
                {
                    yield return(i);
                }
            }
        }
Esempio n. 3
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="factors">Prime factor powers of the number</param>
        /// <returns>-1 if deficient, 0 if perfect, 1 if abundant</returns>
        public static int Perfection(int[] factors)
        {
            var sum   = 0;
            var value = PrimeFactors.Value(factors);

            foreach (var i in ProperDivisors(factors))
            {
                sum += i;
                if (sum > value)
                {
                    return(1);
                }
            }
            return((sum < value) ? -1 : 0);
        }
Esempio n. 4
0
        public void InverseFactorValue(int value)
        {
            var powers = PrimeFactors.Factor(value);

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