面对再一次T掉的问题,我机智地选择了打表。
import java.util.*;
class A {
long[] sum = new long[100005];
public void setSum() {
for (int i = 1; i <= 100000; i++) {
if (i % 3 == 0)
sum[i] = sum[i - 1] + (long) i * (long) i * (long) i;
else
sum[i] = sum[i - 1] + i;
}
}
public long getAns(int n) {
return sum[n];
}
}
public class Main {
public static void main(String[] args) {
int n;
A a = new A();
a.setSum();
Scanner inScanner = new Scanner(System.in);
while (inScanner.hasNextInt()) {
n = inScanner.nextInt();
if (n < 0)
break;
System.out.println(a.getAns(n));
}
}
}