首页 > 其他 > 详细

ProjectEuler 006题

时间:2014-05-26 02:15:24      阅读:338      评论:0      收藏:0      [点我收藏+]

题目:

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 bubuko.com,布布扣 385 = 2640.

Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

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

bubuko.com,布布扣
 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 }
bubuko.com,布布扣

 

ProjectEuler 006题,布布扣,bubuko.com

ProjectEuler 006题

原文:http://www.cnblogs.com/wanghui390/p/3749437.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!