ProjectEuler 006题

题目:

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.

这个也太简单了,不过如果用笔算的话肯定很难,需要思考一番

 1 #include<iostream>
 2 using namespace std;
 3 
 4 int main() {
 5     int N = 100;
 6     int squareofsum = ((1+N)*N/2)*((1+N)*N/2);
 7     int sumofaquare = 0;
 8     for(int i = 1; i <= N; i++) {
 9         sumofaquare += i*i;
10     }
11     cout << squareofsum - sumofaquare << endl;
12     system("pause");
13     return 0;
14 }

 

posted @ 2014-05-24 11:38  soul390  阅读(125)  评论(0编辑  收藏  举报