# 遞推法ide
def sum01(n):遞歸
result = 0數學
for i in range(1, n+1):it
result += iclass
return resultdi
# 遞歸法view
def sum02(n):vi
if n == 1:co
return 1editor
else:
return n + sum02(n-1)
# 數學公式法
def sum03(n):
return n * (1 + n) / 2