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.
这个问题比较好解决有2个公式
一,平方和公式
平方和公式n(n+1)(2n+1)/6
即1^2+2^2+3^2+…+n^2=n(n+1)(2n+1)/6 (注:n^2=n的平方)
二, 求和公式
1+2+..+n = (1+n)n/2
所以上面的就好做了
欧拉项目第六题#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int n = 100; unsigned long int sum1, sum2; sum1 = n * n * (n + 1) * (n + 1) / 4; sum2 = n * (n + 1) * (2*n + 1) /6; printf("%lu", sum1 - sum2); system("PAUSE"); return 0; }