题解 | #等差数列#
等差数列
http://www.nowcoder.com/practice/f792cb014ed0474fb8f53389e7d9c07f
let line;
function func(line) {
let rtnVal;
const n = parseInt(line);
const a1 = 2;
const d = 3;
// 前n项和公式为:Sn=n*a1+n(n-1)d/2或Sn=n(a1+an)/2
rtnVal = n * (a1 + d * (n - 1) / 2);
return rtnVal;
}
while(line = readline()){
print(func(line));
}