본문 바로가기
Algorithm

[구현/수학] 백준 9713 Sum of Odd Sequence - 파이썬(Python)

by jangThang 2022. 12. 10.
반응형

백준 온라인 저지

 

[ Contents ]

     

     

    1. 문제 (링크 참조)

     

    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

     

     

     

    2. 문제 풀이

     N개의 정수가 주어집니다. 그 중 홀수만을 더한 값을 구해야 합니다.

     

     

     

    3. 코드

    # 입력
    T = int(input())
    for _ in range(T):
        N = int(input())
        res = 0
        for i in range(N):
            if i % 2 == 1:
                res += i
        print(res+N)

     

     

    star가 되고나서 Tistory

    반응형

    댓글