예제 #1
0
        public static int NumberOfPrimeUnder(int number)
        {
            int result = 0;

            for (int i = 2; i <= number; i++)
            {
                if (FunctionsMath.IsPrime(i))
                {
                    result++;
                }
            }

            return(result);
        }
예제 #2
0
        public static List <int> GetPrimesBefore(int number)
        {
            List <int> result = new List <int>();

            for (int i = 2; i <= number; i++)
            {
                if (FunctionsMath.IsPrime(i))
                {
                    result.Add(i);
                }
            }

            return(result);
        }
예제 #3
0
        public static bool IsTwinPrime(int number)
        {
            if (number < 2)
            {
                return(false);
            }

            if (number == 2)
            {
                return(true);
            }

            return(FunctionsMath.IsPrime(number) && FunctionsMath.IsPrime(number + 2));
        }
예제 #4
0
        public static Dictionary <int, int> NumberOfPrimesByHundred(int number)
        {
            Dictionary <int, int> result = new Dictionary <int, int>();

            for (int i = 2; i <= number; i++)
            {
                if (FunctionsMath.IsPrime(i))
                {
                    int index = (Math.Abs(i / 100) + 1) * 100;
                    if (result.ContainsKey(index))
                    {
                        result[index]++;
                    }
                    else
                    {
                        result.Add(index, 1);
                    }
                }
            }

            return(result);
        }