Exemplo n.º 1
0
        /// <summary>
        /// Solves the problem
        /// </summary>
        /// <returns></returns>
        public long Solve()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            long         num = ConsecNumbers[this.Size - 1].Key;
            FactorFinder f;

            while (!HasSameConsecutives)
            {
                try
                {
                    num++;
                    //  Console.WriteLine(num);
                    f = new FactorFinder(num);
                    f.FindPrimes(pReader.SmallerThan(num + 1));
                    MoveArray(num, f.Primes.Keys.Count);
                }
                catch (Exception)
                {
                }
            }
            sw.Stop();
            Console.WriteLine("Elapsed: {0}s, {1}ms", sw.Elapsed.Seconds, sw.Elapsed.Milliseconds);
            return(ConsecNumbers[0].Key);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new problem
        /// </summary>
        /// <param name="consecSize">The size of consec numbers</param>
        public DistinctPrimesFactors(int consecSize = 4)
        {
            ConsecNumbers = new KeyValuePair <long, int> [consecSize];
            this.Size     = consecSize;
            FactorFinder f;

            pReader = new PrimeFileReader(new FileInfo(Path.Combine(PRIME_PATH, PRIME_FILE)), new long[] { 0, 10000000 });
            for (int i = 0; i < consecSize; i++)
            {
                f = new FactorFinder(i + 1);
                f.FindPrimes(pReader.SmallerThan(i + 2));
                ConsecNumbers[i] = new KeyValuePair <long, int>(i + 1, f.Primes.Keys.Count);
            }
        }