728x90
9713번: Sum of Odd Sequence
First line of the input contains T, the number of test cases. Each test case contains a single integer N. N is between 1 and 100.
www.acmicpc.net
문제 풀이
주어진 케이스의 입력값마다 1부터 입력값까지의 홀수의 합을 구해 출력해준다.
정답 코드
for _ in range(int(input())) :
n = int(input())
ans = 0
for i in range(1, n + 1, 2) : ans += i
print(ans)
728x90
'Algorithm > PS' 카테고리의 다른 글
[BOJ/백준] 9724 - Perfect Cube [python] (0) | 2023.03.27 |
---|---|
[BOJ/백준] 9723 - Right Triangle [python] (0) | 2023.03.27 |
[BOJ/백준] 9699 - RICE SACK [python] (0) | 2023.03.27 |
[BOJ/백준] 9698 - SAHUR & IMSA’ [python] (0) | 2023.03.27 |
[BOJ/백준] 9635 - Balloons Colors [python] (0) | 2023.03.26 |