コード例 #1
0
        // Returns the n-th prime value, where the 1st prime is 2
        public static int NthPrime(int n)
        {
            if (n <= 1)
            {
                return(2);
            }

            int currN     = 2;
            int currPrime = 3;

            while (currN < n)
            {
                currPrime += 2; // Even numbers can't be prime
                if (Problem003.IsPrime((ulong)currPrime))
                {
                    currN++;
                }
            }

            return(currPrime);
        }