아이공의 AI 공부 도전기

[CodeUp] 1905번 : (재귀함수) 1부터 n까지 합 구하기 (Python)

 

 

Python

 

방법 1 - 메모리 37916 / 시간 23 / 코드 길이 136B

import sys
sys.setrecursionlimit(100000)

를 적지 않으면 

"RuntimeError: maximum recursion depth exceeded" Error가 뜹니다.

 

import sys
sys.setrecursionlimit(100000)

def s(n):
  if n == 1:
    return 1
  return n+s(n-1)  

t = int(input())
print(s(t))

 

공유하기

facebook twitter kakaoTalk kakaostory naver band
loading