public void TestPentagonalNthNumber()
        {
            var expected = 40755;
            var actual   = PentagonalNumberGenerator.NthNumber(165);

            Assert.AreEqual(expected, actual);
        }
예제 #2
0
        static void Main(string[] args)
        {
            // all hexagonal numbers are also triangle numbers
            // only need to find next hexagonal number which is also
            // a pentagonal number

            int p = 166;
            int h = 144;

            BigInteger pNum = PentagonalNumberGenerator.NthNumber(p);
            BigInteger hNum = HexagonalNumberGenerator.NthNumber(h);

            while (pNum != hNum && pNum > 0)
            {
                if (pNum < hNum)
                {
                    p++;
                    pNum = PentagonalNumberGenerator.NthNumber(p);
                }
                else
                {
                    h++;
                    hNum = HexagonalNumberGenerator.NthNumber(h);
                }
            }

            Console.WriteLine(hNum);
            Console.ReadKey();
        }