Problem 6 Sum square difference
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:
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
问题 6 和的平方与平方的和差值
前十个自然数的平方的和为:
而前十个自然数和的平方为:
因此,前十个自然数的平方和与和的平方之间的差是:
求前一百个自然数的平方和与和的平方之间的差
思路分析
自然数的平方的和通项公式
自然数和的平方通项公式
则和的平方与平方和差值通项公式为
代码实现
代码语言:javascript复制/*
* @Author: coder-jason
* @Date: 2022-04-12 10:48:07
* @LastEditTime: 2022-04-12 11:16:45
*/
#include <iostream>
using namespace std;
int main()
{
int n = 100;
long long int ans = n * (n - 1) * (n 1) * (3 * n 2) / 12;
cout << ans;
return 0;
}
答案:25164150