java等差数列求和公式
等差数列
http://www.nowcoder.com/questionTerminal/f792cb014ed0474fb8f53389e7d9c07f
思路:等差数列求和公式
前n项和:Sn = (a1 + an)*n/2
第n项: an = a1 + (n - 1) * 3(公差);
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int n = sc.nextInt(); System.out.println((1 + 3 * n) * n / 2); } } }