Euler_6

Sum square difference

Problem 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.

 

Answer:
25164150
Completed on Fri, 11 Jan 2013, 05:58

Go to the thread for problem 6 in the forum.

 

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 #include <math.h>
 5 
 6 int func(int n)
 7 {
 8     int a = n;
 9     int b = a * n;
10     int c = b * n;
11     int d = c * n;
12 
13     return (3 * d + 2 * c - 3 * b - 2 * a) / 12;
14 }
15 
16 int main(int argc, const char *argv[])
17 {
18     printf("%d\n", func(100));
19 
20     return 0;
21 }
View Code

 

posted @ 2013-05-28 21:54  楼兰故居  阅读(97)  评论(0)    收藏  举报