Exemplo n.º 1
0
        public static long Problem49()
        {
            /*
             * The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three terms are prime, and, (ii) each of the 4-digit numbers are permutations of one another.
             * There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes, exhibiting this property, but there is one other 4-digit increasing sequence.
             * What 12-digit number do you form by concatenating the three terms in this sequence?
             */

            List <long>   primes  = Formulas.PrimeSieve(10000);
            List <long>   numbers = new List <long>();
            List <string> results = new List <string>();

            int limit = 10000;

            foreach (long n in primes)
            {
                if (n > 1000)
                {
                    numbers.Add(n);
                }
            }

            for (int i = 0; i < numbers.Count(); i++)
            {
                for (int j = i + 1; j < numbers.Count; j++)
                {
                    long k = numbers[j] + (numbers[j] - numbers[i]);

                    if (k < limit && numbers.Contains(k))
                    {
                        if (Formulas.IsPermutation((int)numbers[i], (int)numbers[j]) && Formulas.IsPermutation((int)numbers[i], (int)k))
                        {
                            if (numbers[i] != 1487)
                            {
                                results.Add(String.Concat(numbers[i], numbers[j], k));
                            }
                        }
                    }
                }
            }
            return(Int64.Parse(results[0]));
        }
Exemplo n.º 2
0
        public static long Problem52()
        {
            /*
             * It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.
             * Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits
             */
            int  x  = 0;
            bool ok = true;

            do
            {
                x++;
                ok = true;
                for (int i = 2; i < 7; i++)
                {
                    if (!Formulas.IsPermutation(x * i, x))
                    {
                        ok = false;
                    }
                }
            } while (!ok);

            return(x);
        }