https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1243
這題其實用long就可以了這題有兩種解法 第一種是動態規劃先把5000內所有立方算出後來再相加 第二種解法是利用公式解 (xx(x+1)*(x+1))/4
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
BigInteger arr[]=new BigInteger[50000];
for(int i=1;i<=50000;i++){
BigInteger x=new BigInteger(Integer.toString(i));
arr[i-1]=x.pow(3);
}
while(scn.hasNext()){
int n=scn.nextInt();
BigInteger tot=new BigInteger("0");
for(int i=0;i<n;i++)
tot=tot.add(arr[i]);
System.out.println(tot);
}
}
/*題目:Q10302: Summation of Polynomials
作者:1010
時間:西元 2016 年 10 月 */
}