等差数列 2,5,8,11,14。。。。
(从 2 开始的 3 为公差的等差数列)
输出求等差数列前n项和
数据范围:
n = int(input()) def Arithmetic(n): if n == 1: return 2 return Arithmetic(n-1) + 3*(n-1) + 2 print(Arithmetic(n))
n = int(input()) ls = {(i*3-1) for i in range(1,n+1)} print(sum(ls))
n =int(input()) l =[] res = 0 for i in range(2+3*n): if i ==2: l.append(i) elif (i-2) %3 == 0: l.append(i) for j in range(n): res += l[j] print(res)用绕弯子的方式写代码