Exemplo n.º 1
0
        public static (int, int) GetCoefficientsForQuadraticExpressionWhichProducesMaximumNumberOfPrimes(int maxModulusOfCoefficients)
        {
            var longestSequenceOfPrimes        = 0;
            var coefficientsForLongestSequence = (0, 0);

            foreach (int a in Enumerable.Range(-maxModulusOfCoefficients + 1, 2 * maxModulusOfCoefficients - 2))
            {
                foreach (int b in Enumerable.Range(1, maxModulusOfCoefficients))
                {
                    var quadraticFormula = GetQuadraticFormule(a, b);
                    var n = 0;

                    while (PrimeHelper.IsPrime(quadraticFormula(n)))
                    {
                        n++;
                    }

                    if (n > longestSequenceOfPrimes)
                    {
                        longestSequenceOfPrimes        = n;
                        coefficientsForLongestSequence = (a, b);
                    }
                }
            }

            return(coefficientsForLongestSequence);
        }
Exemplo n.º 2
0
        public static long GetSolutionOfProblem49()
        {
            var arithmeticSequences     = PrimeHelper.ArithmeticPrimePermutationsWith4Digits();
            var sequenceWeAreLookingFor = arithmeticSequences[arithmeticSequences.Keys.ToList().Where(number => number != 1487).Single()];

            return(long.Parse(sequenceWeAreLookingFor[0].ToString() + sequenceWeAreLookingFor[1].ToString() + sequenceWeAreLookingFor[2].ToString()));
        }
Exemplo n.º 3
0
        public static long GetSolutionOfProblem47()
        {
            var consecutiveNumbers           = 4;
            var numberOfDistinctPrimeFactors = 4;

            return(PrimeHelper.GetFirstNumberOfConsecutiveNumbersToHaveMDistinctPrimeFactors(consecutiveNumbers, numberOfDistinctPrimeFactors));
        }
Exemplo n.º 4
0
        public static long GetLengthOfNumberSpiralForWhichPercentageOfPrimesOnDiagonalsIsLowerThanLimit(int desiredUpperBoundPercentagePrimes)
        {
            var numberOfDiagonalNumbers   = 5;
            var numberOfPrimesOnDiagonals = 3;

            int increment       = 2;
            int currentPosition = 9;

            while (!(numberOfPrimesOnDiagonals * 100 <= numberOfDiagonalNumbers * desiredUpperBoundPercentagePrimes))
            {
                increment += 2;

                // The odd squares lie on the bottom right diagonal, so these cannot be prime.
                for (int i = 0; i < 3; i++)
                {
                    currentPosition += increment;

                    if (PrimeHelper.IsPrime(currentPosition))
                    {
                        numberOfPrimesOnDiagonals++;
                    }
                }

                currentPosition         += increment;
                numberOfDiagonalNumbers += 4;
            }

            return(increment + 1);
        }
Exemplo n.º 5
0
        public static int GetNumberOfDivisors(long n)
        {
            var numberOfDivisors   = 1;
            var primeFactorization = PrimeHelper.GetPrimeFactorization(n);

            foreach (int key in primeFactorization.Keys)
            {
                numberOfDivisors *= primeFactorization[key] + 1;
            }

            return(numberOfDivisors);
        }
Exemplo n.º 6
0
        public static (int, int) ToLowestTerms(int numerator, int denominator)
        {
            var primeFactorizationNumerator   = PrimeHelper.GetPrimeFactors(numerator);
            var primeFactorizationDenominator = PrimeHelper.GetPrimeFactors(denominator);

            var commonPrimes = primeFactorizationNumerator.Where(prime => primeFactorizationDenominator.Remove(prime));

            foreach (int prime in commonPrimes)
            {
                numerator   /= prime;
                denominator /= prime;
            }

            return(numerator, denominator);
        }
Exemplo n.º 7
0
 public static long GetSolutionOfProblem37()
 {
     return(PrimeHelper.GetAllTruncatablePrimes().Sum());
 }
Exemplo n.º 8
0
        public static long GetSolutionOfProblem35()
        {
            var max = 1000000;

            return(PrimeHelper.GetListOfCircularPrimesBelowMax(max).Count());
        }
Exemplo n.º 9
0
 public static long GetSolutionOfProblem97()
 {
     return(PrimeHelper.LastTenDigitsOfMassiveNonMersennePrimeProblem97());
 }
Exemplo n.º 10
0
        public static long GetSolutionOfProblem69()
        {
            var max = 1000000;

            return(PrimeHelper.HighestProductOfFirstPrimesBelowMax(max));
        }
Exemplo n.º 11
0
        public static long GetSolutionOfProblem51()
        {
            var desiredSizeOfFamily = 8;

            return(PrimeHelper.FirstPrimeWhichHasDesiredSizeOfFamilyByReplacingSomeDigitsBySameNumber(desiredSizeOfFamily));
        }
Exemplo n.º 12
0
        public static long GetSolutionOfProblem50()
        {
            var max = 1000000;

            return(PrimeHelper.PrimeBelowMaxWhichCanBeWrittenAsSumOfMostConsectivePrimes(max));
        }
Exemplo n.º 13
0
 public static long GetSolutionOfProblem46()
 {
     return(PrimeHelper.GetFirstCounterExampleGoldbachsOtherConjecture());
 }
Exemplo n.º 14
0
 private static List <long> GetPandigitalPrimes(List <char> characterAllowedTouse)
 {
     return(GetPandigitalNumbers(characterAllowedTouse)
            .Select(number => long.Parse(number)).Where(number => PrimeHelper.IsPrime(number)).ToList());
 }