题解 | #等差数列#
等差数列
http://www.nowcoder.com/practice/f792cb014ed0474fb8f53389e7d9c07f
思路:等差数列求和公式Sn=n*(a1+an)/2
public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNextInt()) { // 注意 while 处理多个 case int N = in.nextInt(); int a1=2; int an=2+3*(N-1); System.out.println(N*(a1+an)/2); } }