标签:style class blog c code java
题目:
The sum of the squares of the first ten natural numbers is,
The square of the sum of the first ten natural numbers is,
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 }
ProjectEuler 006题,布布扣,bubuko.com
标签:style class blog c code java
原文地址:http://www.cnblogs.com/wanghui390/p/3749437.html