Project Euler 6

 

/**

 * The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385

 * The square of the sum of the

 * first ten natural numbers is, (1 + 2 + ... + 10)2 = 552 = 3025

 * Hence the difference between the sum of the squares of

 * the first ten natural numbers and the square of the sum is 3025 385 = 2640.

 * Find the difference between the sum of

 * the squares of the first one hundred natural numbers and the square of the sum.

 *

 * @author songjie.dongsj 2012-3-26 上午10:22:35

 */

publicclassProblemSix{

 

    publicstaticvoidmain(String[]args){

        intm=1;

        intsum=0;

        intsum4seriesN=100*(100+1)/2;

        for(;m<100;m++){

            sum+=m*(sum4seriesN-m*(m+1)/2);

        }

        System.out.println(sum4seriesN+" "+sum*2);

    }

}

 

推導了n*m多項式的數列,算是土鱉的方法,不過我還搞了半天,自然數的平方和sum(n)我推導不出來。。。

以前讀高中最喜歡的就是解數列相關的題。。。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章