URL : https://www.acmicpc.net/problem/1964

 

1964번: 오각형, 오각형, 오각형…

첫째 줄에 N(1 ≤ N ≤ 10,000,000)이 주어진다.

www.acmicpc.net

return 타입을 int로해서 틀린문제..

long타입으로 변경 후 정답

using System;

namespace baek1964
{
    class Program
    {
        static long GetDotTotal(int N, int index)
        {
            if (N == 1)
            {
                return 5;
            }

            else if (index == 1)
            {
                return 5 + GetDotTotal(N, index + 1);
            }

            else if (index == N)
            {
                return index * 3 + 1;
            }

            return index * 3 + 1 + GetDotTotal(N, index + 1);
        }
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            Console.WriteLine(GetDotTotal(N, 1) % 45678);
        }
    }
}

+ Recent posts