蓝桥杯、入门训练、序列求和

来源:互联网 发布:java 轻量级的orm框架 编辑:程序博客网 时间:2024/04/27 17:04
import java.util.*;

public class Main{

public static void main(String[] args) {
Scanner s = new Scanner(System.in);
long n = s.nextInt();
long result = 0;
if(n%2==0){ //如果n为偶数,结果为n/2倍的n+1
result = (n/2+n/2+1)*n/2;
}else{ //如果n为奇数,结果为n/2倍的处于中间那个数加上它本身
result = n/2*(n/2+1)+n/2+1;
}
System.out.println(result);
}


}
0 0
原创粉丝点击