public void PrimeFactorsNonPrime() { var expected = 5; var actual = Factorization.PrimeFactors(6546235646418).Count(); Assert.Equal(expected, actual); }
public void PrimeFactorsBigInteger() { var expected = new BigInteger[] { 2, 3, 13, 163, 514884037 }; var actual = Factorization.PrimeFactors(new BigInteger(6546235646418)); Assert.True(expected.SequenceEqual(actual)); }
public void PrimeFactorsPrime() { var expected = 1; var actual = Factorization.PrimeFactors(112272535095293).Count(); Assert.Equal(expected, actual); }
public void PrimeFactorsBigIntegerZero() { var expected = new BigInteger[] { }; var actual = Factorization.PrimeFactors(BigInteger.Zero); Assert.True(expected.SequenceEqual(actual)); }
public void PrimeFactorsLong() { var expected = new long[] { 2, 2, 5, 103 }; var actual = Factorization.PrimeFactors(2060L); Assert.True(expected.SequenceEqual(actual)); }
public void PrimeFactorsLongZero() { var expected = new long[] { }; var actual = Factorization.PrimeFactors(0L); Assert.True(expected.SequenceEqual(actual)); }
public void PrimeFactorsIntZero() { var expected = new int[] { }; var actual = Factorization.PrimeFactors(0); Assert.True(expected.SequenceEqual(actual)); }
/// <summary> /// Returns the product of the distinct prime factors of n /// </summary> /// <param name="n"></param> /// <returns></returns> public static long Rad(long n) { if (n == 1) { return(1); } return(Factorization .PrimeFactors(n) .Distinct() .Aggregate((prod, next) => prod * next)); }