Beispiel #1
0
        /// <summary>
        /// Solve the problem
        /// </summary>
        /// <returns>The sum result</returns>
        private long Solve()
        {
            PrimeFactorNode        n;
            long                   res = 1;
            int                    count;
            List <long>            factors;
            Dictionary <long, int> factorCount = new Dictionary <long, int>();

            for (long i = this.Number; i >= 2; i--)
            {
                factors = new List <long>();
                n       = new PrimeFactorNode(i, 2);
                n.GetFactors(ref factors);
                foreach (long f in factors)
                {
                    count = factors.Count(x => x == f);
                    if (factorCount.ContainsKey(f) && factorCount[f] < count)
                    {
                        factorCount[f] = count;
                    }
                    else if (!factorCount.ContainsKey(f))
                    {
                        factorCount.Add(f, count);
                    }
                }
            }
            foreach (long prime in factorCount.Keys)
            {
                res *= (long)Math.Pow(prime, factorCount[prime]);
            }
            return(res);
        }
Beispiel #2
0
        /// <summary>
        /// Solve the problem
        /// </summary>
        /// <returns>The sum result</returns>
        private long Solve()
        {
            PrimeFactorNode fN = new PrimeFactorNode(this.Number);

            return(fN.MaxPrime);
        }