-
8393 1~n 합코테 대비 python/백준 2023. 1. 30. 18:22
#1~n의 합 #solution 1 #단순히 포문으로 더한다. n=int(input()) sum=0 for i in range(1,n+1): sum+=i print(sum) #solution 2 #((n)*(n+1))/2 공식 사용 # 타입 주의!!!! n=int(input()) print(int(((n)*(n+1))/2))
# 두 풀이모두 시간과 메모리 같음!!
'코테 대비 python > 백준' 카테고리의 다른 글
15552 import sys (0) 2023.01.30 25304 합,곱 (1) 2023.01.30 10950 함수만들기 (0) 2023.01.30 21315 완전탐색 블루트포스 ==> 다시풀기 (0) 2023.01.27 21278 bfs ==> 다시 풀어보기 (0) 2023.01.27