본문 바로가기

코딩

[Python] 백준 #2355. 시그마

https://www.acmicpc.net/problem/2355

 

2355번: 시그마

첫째 줄에 두 정수 A, B가 주어진다. (-2,147,483,648 ≤ A, B ≤ 2,147,483,647)

www.acmicpc.net

 

# 2355 - Python 3

import sys

input = sys.stdin.readline

a, b = map(int, input().split())

if a > b:
    a, b = b, a

sum_ab = b * (b + 1) // 2 - a * (a - 1) // 2    # 시그마 공식 사용

print(sum_ab)

'코딩' 카테고리의 다른 글

[Python] 백준 #2558. A + B - 2  (0) 2023.03.22
[Python] 백준 #11399. ATM  (0) 2023.03.22
[Python] 백준 #11047. 동전 0  (0) 2023.03.22
[Python] 백준 #15932. 수학은 비대면강의입니다  (0) 2023.03.22
[Python] 백준 #14215. 세 막대  (0) 2023.03.22