문제 링크입니다: https://www.acmicpc.net/problem/2355
2355번: 시그마
첫째 줄에 두 정수 A, B가 주어진다. (-2,147,483,648 ≤ A, B ≤ 2,147,483,647)
www.acmicpc.net
가우스의 시그마 공식을 적용하면 되는 문제였습니다.
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> | |
#include <algorithm> | |
using namespace std; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
long long A, B; | |
cin >> A >> B; | |
if (A > B) | |
{ | |
swap(A, B); | |
} | |
cout << (A + B) * (B - A + 1) / 2 << "\n"; | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 1816번 암호 키 (8) | 2019.11.25 |
---|---|
백준 3671번 산업 스파이의 편지 (0) | 2019.11.24 |
백준 9506번 약수들의 합 (0) | 2019.11.11 |
백준 1024번 수열의 합 (4) | 2019.11.11 |
백준 1834번 나머지와 몫이 같은 수 (0) | 2019.11.11 |