Ejemplo n.º 1
0
        public static int SmallestMultiple(int n)
        {
            PrimeFunctions.GeneratePrimesTillNToList(n);
            List <int> FactorList = new List <int>();

            //Loop until highest multiple
            for (int i = 2; i <= n; i++)
            {
                //Find all the factors of the number
                List <int> factors = PrimeFunctions.PrimeFactor(i, false);
                //If the list of factors doesn't contain the factor or as many factors, then add it to the list
                foreach (int factor in factors)
                {
                    if (MiscFunctions.ReturnDistinctCountList(factors, factor) > MiscFunctions.ReturnDistinctCountList(FactorList, factor))
                    {
                        FactorList.Add(factor);
                    }
                }
            }
            //Loop through the minimum required factors and multiply them all
            int mult = 1;

            foreach (int factor in FactorList)
            {
                mult *= factor;
            }
            return(mult);
        }
Ejemplo n.º 2
0
        public static int DistinctPrimeFactors()
        {
            PrimeFunctions.GeneratePrimesToList(100000);
            int i     = 2;
            int count = 0;

            while (count < 4)
            {
                i++;
                List <int>    primes  = PrimeFunctions.PrimeFactor(i);
                HashSet <int> factors = MiscFunctions.ListToHash(primes);
                if (factors.Count == 4)
                {
                    count++;
                }
                else
                {
                    count = 0;
                }
            }
            return(i - 3);
        }
Ejemplo n.º 3
0
 public static int LargestPrimeFactor(long n)
 {
     //Return the largest number in the list of prime factors
     return(PrimeFunctions.PrimeFactor(n).Max());
 }