문제 링크입니다: https://www.acmicpc.net/problem/1964
1964번: 오각형, 오각형, 오각형…
첫째 줄에 N(1≤N≤10,000,000)이 주어진다.
www.acmicpc.net
규칙을 찾아보면 아래와 같습니다.
1. 처음 오각형은 점 5개로 시작합니다.
2. 이후부터는 i번째 단계에서 점이 (i + 1) * 3 - 2 만큼 추가되는 것을 알 수 있습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
const int MOD = 45678; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int N; | |
cin >> N; | |
int result = 5; | |
for (int i = 1; i < N; i++) | |
{ | |
result = (result + (i + 2) * 3 - 2) % MOD; | |
} | |
cout << result << "\n"; | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 1834번 나머지와 몫이 같은 수 (0) | 2019.11.11 |
---|---|
백준 4504번 배수 찾기 (0) | 2019.11.10 |
백준 1712번 손익분기점 (3) | 2019.11.10 |
백준 12018번 Yonsei TOTO (0) | 2019.11.09 |
백준 1781번 컵라면 (2) | 2019.11.09 |