public void InverseFactorTest() { for (var i = 1; i < 1000; i++) { var powers = PrimeFactors.Factor(i); Assert.That(PrimeFactors.Value(powers), Is.EqualTo(i)); } }
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)); }
/// <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); } } }
/// <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))); }
/// <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))); }
/// <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))); }
public void InverseFactorValue(int value) { var powers = PrimeFactors.Factor(value); Assert.That(PrimeFactors.Value(powers), Is.EqualTo(value)); }