[백준/파이썬] 14545번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 14545번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
Do you know a game called “La cave aux énigmes”? One of its questions is to find the number of squares contained in a grid square of length l. A grid square of length 4 will look like this:
The total number of squares that can be seen in this image is 30. Your task is to find the total number of squares which can be seen in an image of a grid square of length l.
입력 요약
The input will begin with a single integer P on the first line, indicating the number of cases that will follow.
The remaining lines of the input will consist of one integer l per line, which is the grid square length. …
출력 요약
For each integer l, you should output the total number of squares which can be seen in an image of a grid square of length l, with one line of output for each line of input.
코드
l=[0]
for i in range(1,1000001):l.append(l[-1]+i*i)
for T in range(int(input())):
print(l[int(input())])
설명
핵심은 구현 관점에서 Do you know a game called “La cave aux énigmes”? One of its questions is to find the number of squares contained in a grid square of length l. …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기