コード例 #1
0
        public static int CirculuarPrimes(int n)
        {
            PrimeFunctions.GeneratePrimesTillNToList(1000000);
            PrimeFunctions.ConvertToHash();

            int count = 0;

            for (int i = 2; i < n; i++)
            {
                List <int> rots  = CombinatoricFunctions.rotations(i);
                bool       prime = true;
                foreach (int rot in rots)
                {
                    if (!PrimeFunctions.PrimeListHash.Contains(rot))
                    {
                        prime = false;
                        break;
                    }
                }
                if (prime)
                {
                    count++;
                    //Console.WriteLine(i);
                }
            }
            return(count);
        }
コード例 #2
0
        public static int SmallestMultiple(int n)
        {
            PrimeFunctions.GeneratePrimesTillNToList(n);
            List <int> FactorList = new List <int>();

            //Loop until highest multiple
            for (int i = 2; i <= n; i++)
            {
                //Find all the factors of the number
                List <int> factors = PrimeFunctions.PrimeFactor(i, false);
                //If the list of factors doesn't contain the factor or as many factors, then add it to the list
                foreach (int factor in factors)
                {
                    if (MiscFunctions.ReturnDistinctCountList(factors, factor) > MiscFunctions.ReturnDistinctCountList(FactorList, factor))
                    {
                        FactorList.Add(factor);
                    }
                }
            }
            //Loop through the minimum required factors and multiply them all
            int mult = 1;

            foreach (int factor in FactorList)
            {
                mult *= factor;
            }
            return(mult);
        }
コード例 #3
0
        public static int PandigitalPrime(int n)
        {
            List <int> PanPrimes = new List <int>();

            PrimeFunctions.GeneratePrimesTillNToList(n);
            for (int i = 0; i < PrimeFunctions.PrimeList.Count; i++)
            {
                if (MiscFunctions.IsPandigital(PrimeFunctions.PrimeList[i]))
                {
                    PanPrimes.Add(PrimeFunctions.PrimeList[i]);
                }
            }
            return(PanPrimes.Max());
        }
コード例 #4
0
        public static int QuadraticPrimes(int n)
        {
            PrimeFunctions.GeneratePrimesTillNToList(n * n);
            PrimeFunctions.ConvertToHash();
            int maxi      = 0;
            int maxj      = 0;
            int maxprimes = 0;

            for (int i = (n * -1); i < n; i++)
            {
                for (int j = (n * -1); j < n; j++)
                {
                    if (numquadprimes(i, j) > maxprimes)
                    {
                        maxprimes = numquadprimes(i, j);
                        maxi      = i;
                        maxj      = j;
                    }
                }
            }
            return(maxi * maxj);
        }