[백준/파이썬] 11522번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 11522번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
For this problem you will compute various running sums of values for positive integers.
입력 요약
The first line of input contains a single integer P, (1 ≤ P ≤ 10000), which is the number of data sets that follow. Each data set should be processed identically and independently.
Each data set consists of a single line of input. …
출력 요약
For each data set there is one line of output. The single output line consists of the data set number, K, followed by a single space followed by three space separated integers S1, S2 and S3 such that:
- S1 = The sum of the first N positive integers. …
코드
import sys;read=sys.stdin.readline
l=[]
for T in range(int(read())):
t,n=map(int,read().split())
l.append(f'{t} {n*(n+1)//2} {n*n} {n*(n+1)}')
print('\n'.join(l))
설명
핵심은 구현 관점에서 For this problem you will compute various running sums of values for positive integers.를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기