Example #1
0
        /// <summary>
        /// Main Thread
        /// </summary>
        static void Main()
        {
            const int MAX_VALUE = 1000000;

            Dictionary <Int64, int> Solutions = new Dictionary <long, int>();

            PrimeNumber.CalculateTermsUntilValue(MAX_VALUE);


            int   i           = 1;
            Int64 primeNumber = PrimeNumber.GetPrimeTerm(i);

            while (primeNumber < MAX_VALUE)
            {
                int index = 1;

                while (PrimeNumber.GetPrimeTerm((int)index) < System.Math.Sqrt(primeNumber))
                {
                    Int64 sum   = 0;
                    int   count = 0;
                    int   j     = index;

                    while (sum < primeNumber)
                    {
                        sum += PrimeNumber.GetPrimeTerm((int)j);
                        count++;
                        j++;
                    }

                    if (sum == primeNumber)
                    {
                        if (Solutions.ContainsKey(primeNumber))
                        {
                            if (count > Solutions[primeNumber])
                            {
                                Solutions[primeNumber] = count;
                            }
                        }

                        else
                        {
                            Solutions.Add(primeNumber, count);
                        }
                    }

                    index++;
                }

                i++;
                primeNumber = PrimeNumber.GetPrimeTerm(i);
            }

            Console.WriteLine("Solution: {0}", Solutions.Aggregate((l, r) => l.Value > r.Value ? l : r).Key);
        }
Example #2
0
        /// <summary>
        /// Main Thread
        /// </summary>
        static void Main()
        {
            PrimeNumber.CalculateTermsUntilValue(MAX_NUMBER);

            List <Int64> solution = (from p in PrimeNumber.GetListPrimes()
                                     where ((p.ToString().Length == 4) || (p.ToString().Length == 7)) &&
                                     Pandigital.IsPandigital(p)
                                     select p).ToList();

            Console.WriteLine("Solution: {0}", solution.Max());
        }
Example #3
0
        /// <summary>
        /// Main Thread
        /// </summary>
        static void Main()
        {
            const int MAX_NUMBER = 1000000;

            PrimeNumber.CalculateTermsUntilValue(MAX_NUMBER);

            int result = (from p in PrimeNumber.GetListPrimes()
                          where PrimeNumber.IsCircularPrime(p)
                          select p).Count();

            Console.WriteLine("Solution: {0}", result);
        }
Example #4
0
        /// <summary>
        /// Main Thread
        /// </summary>
        static void Main()
        {
            PrimeNumber.CalculateTermsUntilValue(10000);

            List <Int64> primes = PrimeNumber.GetListPrimes();

            string solution = (from p1 in primes
                               from p2 in primes
                               from p3 in primes
                               where p1 > 1487 && p2 - p1 == 3330 && p3 - p2 == 3330 &&
                               Permutation.ArePermutations(p1, p2) &&
                               Permutation.ArePermutations(p2, p3)
                               select p1.ToString() + p2.ToString() + p3.ToString()).FirstOrDefault();

            Console.WriteLine("Solution: {0}", solution);
        }
Example #5
0
        static void Main()
        {
            const int MAX_NUMBER = 50000000;

            PrimeNumber.CalculateTermsUntilValue((int)(Math.Sqrt(MAX_NUMBER) + 1));

            HashSet <double> solutions = new HashSet <double>();

            List <Int64> primes = PrimeNumber.GetListPrimes();

            for (int i = 0; i < primes.Count; i++)
            {
                double firstPow = Math.Pow(primes[i], 2);

                if (firstPow <= MAX_NUMBER)
                {
                    for (int j = 0; j < primes.Count; j++)
                    {
                        double secondPow = Math.Pow(primes[j], 3);

                        if (firstPow + secondPow <= MAX_NUMBER)
                        {
                            for (int k = 0; k < primes.Count; k++)
                            {
                                double result = firstPow + secondPow + Math.Pow(primes[k], 4);
                                if (result <= MAX_NUMBER)
                                {
                                    solutions.Add(result);
                                }
                            }
                        }
                    }
                }
            }

            Console.WriteLine("Solution: {0}", solutions.Count());
        }
Example #6
0
        /// <summary>
        /// Main Thread
        /// </summary>
        static void Main()
        {
            PrimeNumber.CalculateTermsUntilValue(MAX_VALUE);

            Console.WriteLine("Solution: {0}", PrimeNumber.GetListPrimes().Where(p => (p < MAX_VALUE)).Sum());
        }