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);
}
}
}
'알고리즘 문제 풀이' 카테고리의 다른 글
[Javascript] 백준 11720번 숫자의합 (0) | 2022.06.29 |
---|---|
[Javascript] 백준 2588번 곱셈 (0) | 2022.06.26 |
[백준 알고리즘] C# 이상한곱셈, 1225번 (0) | 2021.07.23 |
[프로그래머스] C# 음양 더하기 (0) | 2021.07.23 |
[백준 알고리즘] C# 시험 점수 5596번 (0) | 2021.07.23 |