Exemplo n.º 1
0
        public static IEnumerable <ulong> GetPrimeFactors(this ulong num, PrimeCalculator cal)
        {
            cal.ExtendToMinimumGT(num / 2);     // so that cal.Primes is populated with all prime factors needed

            if (cal.IsPrimeAutoExpand(num))     // Don't need to consider num which is a prime.
            {
                yield break;
            }

            foreach (var prime in cal.Primes)
            {
                while (num % prime == 0)
                {
                    yield return(prime);

                    num /= prime;
                }

                if (num == 1)
                {
                    break;
                }
            }
        }
Exemplo n.º 2
0
 public static IEnumerable <ulong> GetDistinctPrimeFactors(this ulong num, PrimeCalculator cal)
 {
     return(num.GetPrimeFactors(cal).Distinct());
 }