当前位置: 代码迷 >> 综合 >> HDOJ 2132 An easy problem
  详细解决方案

HDOJ 2132 An easy problem

热度:40   发布时间:2023-10-21 18:52:16.0

HDACM 2132

注意sum(i-1)+i*i*i时,(long)i*i*i

import java.util.Scanner;public class Main {
    public static void main(String[] args) {long sum[] = new long [100001];for (int i = 1; i < sum.length; i++) {if (i%3==0) {sum[i] = sum[i-1]+(long)i*i*i;}else{sum[i] = sum[i-1]+(long)i;}}Scanner sc = new Scanner(System.in);while(sc.hasNext()){int n = sc.nextInt();if (n<0) {break;}System.out.println(sum[n]);}sc.close();}
}
  相关解决方案