数学思路,转化为等差数列求和,直接用公式计算求解,而不是循环遍历,附python代码

import sys
for s in sys.stdin:
    try:
        n = int(s)
        d = 3
        a1 = 2
        an = a1 + (n-1)*d
        sums = (a1 + an)/2 * n
        print(int(sums))
    except:
        print(-1)