码迷,mamicode.com
首页 > 其他好文 > 详细

ProjectEuler 006题

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

标签:style   class   blog   c   code   java   

题目:

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题

标签:style   class   blog   c   code   java   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!