解题思路:
1+2+3+.....+n如果用for循环来写的话,系统肯定会超时,所以直接用数学中的求和公式 n*(n+1)/2即可
解题代码:
public static void main(String[] args) { Scanner input = new Scanner (System.in); long n=input.nextLong(); long sum=0; sum=n*(n+1)/2; System.out.println(sum); }