题解 | #等差数列#
等差数列
http://www.nowcoder.com/practice/f792cb014ed0474fb8f53389e7d9c07f
while True:
try:
num = int(input())
sum_num = 2
b = [2] #初始为2
for i in range(1,num): #从等差数列第二个数,即5开始放入b
sum_num += 3
b.append(sum_num)
sum_num = 0 #sum_num 归零
for i in range(len(b)):
sum_num += b[i] #等差数列求和
print(sum_num)
except:
break
华为机试题解(prod.by kedao) 文章被收录于专栏
华为实习机试题解