public void GetPrimeFactors_Returns_Enumerator_To_Prime_Factors_In_Exponential_Form() { var expectedPrimeFactors = new[] { new Exponent(2, 1), new Exponent(5, 2), new Exponent(17, 1), }; PrimeMath.GetPrimeFactors(850).Should().BeEquivalentTo(expectedPrimeFactors); }
/// <summary> /// Run solution for problem 47. /// </summary> /// <param name="consecutiveNumbersTarget"> /// Target of consecutive numbers that meets <paramref name="distinctPrimeFactorCount"/>. /// </param> /// <param name="distinctPrimeFactorCount">Number of district prime factors.</param> /// <returns> /// First number in <paramref name="consecutiveNumbersTarget"/> that is made up of /// <paramref name="distinctPrimeFactorCount"/>. /// </returns> public static int Run(int consecutiveNumbersTarget, int distinctPrimeFactorCount) { var previousMatchedNumber = 0; var consecutiveNumberCount = 0; for (var i = 0; consecutiveNumberCount < consecutiveNumbersTarget; i += 1) { var primeFactors = PrimeMath.GetPrimeFactors(i); if (primeFactors.Count() == distinctPrimeFactorCount && (previousMatchedNumber == 0 || previousMatchedNumber == i - 1)) { previousMatchedNumber = i; consecutiveNumberCount += 1; } else if (consecutiveNumberCount != 0) { previousMatchedNumber = 0; consecutiveNumberCount = 0; } } return(previousMatchedNumber - consecutiveNumbersTarget + 1); }
/// <summary> /// Run solution for problem 3. /// </summary> /// <param name="number">Input number.</param> /// <returns>Largest prime factor of <paramref name="number"/>.</returns> public static int Run(int number) { var primeFactors = PrimeMath.GetPrimeFactors(number); return(primeFactors.ToArray()[^ 1].BaseValue);