Exemplo n.º 1
0
        public static int OddComposite()
        {
            int           comp       = 0;
            List <int>    primes     = PrimeFunctions.GeneratePrimes(10000);
            HashSet <int> primeshash = MiscFunctions.ListToHash(primes);
            List <int>    squares    = SpecialSequences.squares(1000);

            HashSet <int> squareshash = MiscFunctions.ListToHash(squares);
            int           i           = 3;
            bool          found       = false;

            while (comp == 0)
            {
                found = false;
                i    += 2;
                if (primeshash.Contains(i))
                {
                    continue;
                }
                for (int j = 0; j < primes.Count; j++)
                {
                    if (primes[j] > i)
                    {
                        break;
                    }
                    for (int k = 0; k < squares.Count; k++)
                    {
                        if (squares[k] * 2 > i)
                        {
                            break;
                        }
                        if (primes[j] + (squares[k] * 2) == i)
                        {
                            found = true;
                        }
                    }
                }
                if (!found)
                {
                    comp = i;
                }
            }
            return(comp);
        }
Exemplo n.º 2
0
        public static int DistinctPrimeFactors()
        {
            PrimeFunctions.GeneratePrimesToList(100000);
            int i     = 2;
            int count = 0;

            while (count < 4)
            {
                i++;
                List <int>    primes  = PrimeFunctions.PrimeFactor(i);
                HashSet <int> factors = MiscFunctions.ListToHash(primes);
                if (factors.Count == 4)
                {
                    count++;
                }
                else
                {
                    count = 0;
                }
            }
            return(i - 3);
        }