[파이썬][백준 8393번] 합
1. 문제Permalink
[Bronze III] 합 - 8393Permalink
성능 요약Permalink
메모리: 30864 KB, 시간: 76 ms
분류Permalink
구현(implementation), 수학(math)
문제 설명Permalink
n이 주어졌을 때, 1부터 n까지 합을 구하는 프로그램을 작성하시오.
입력Permalink
첫째 줄에 n (1 ≤ n ≤ 10,000)이 주어진다.
출력Permalink
1부터 n까지 합을 출력한다.
출처: 백준, https://https://www.acmicpc.net/
2. 해결방법 시간복잡도Permalink
- 단순 코딩 O(N)
3. 문제 해결 및 코드Permalink
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
a = 0 | |
for i in range(n + 1): | |
a += i | |
print(a) |
-
주석을 참고하면서 이해를 돕습니다.Permalink
4. 알고리즘 및 해설Permalink
- 반복문을 통해 0에서 해당 값까지 더해준다.
- 최종 결과값을 출력한다.