Project Euler__problem 6
2017-10-11 18:35
417 查看
Problem 6
Sum square difference
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.
平方的和与和的平方之差
前十个自然数的平方的和是12 + 22 + … + 102 = 385
前十个自然数的和的平方是
(1 + 2 + … + 10)2 = 552 = 3025
因此前十个自然数的平方的和与和的平方之差是 3025 − 385 = 2640。
求前一百个自然数的平方的和与和的平方之差。
这次做到第6题,感觉没有什么好总结的,
比较简单的一道题目,也算是这样吧
答案是25164150
#include<iostream>
int fun1(int n)
{
int sum = 0;
int i;
for (i = 1; i <= n; i++)
{
sum = sum + i*i;
}
return sum;
}
int fun2(int n)
{
int sum = 0;
int i;
for (i = 1; i <= n; i++)
sum = sum + i;
return sum*sum;
}
int main()
{
int x1, x2;
x1 = fun1(100);
x2 = fun2(100);
std::cout << x2 << "-" << x1 << "=" << x2 - x1 << std::endl;
system("pause");
return 0;
}
相关文章推荐
- [Project Euler]加入欧拉 Problem 6
- [Project Euler] Problem 10
- [Project Euler] Problem 28
- 欧拉项目(Project Euler)Problem 1
- Project Euler – Problem 17
- [Project Euler] Problem 49
- [Project Euler] Problem 51
- [Project Euler] Problem 60 Deep First, Milestone, New Start
- Project Euler :Problem 54 Poker hands
- Project Euler:Problem 25 1000-digit Fibonacci number
- Project Euler:Problem 46 Goldbach's other conjecture
- Project Euler:Problem 58 Spiral primes
- Project Euler:Problem 68 Magic 5-gon ring
- Project Euler:Problem 88 Product-sum numbers
- 【Project Euler】【Problem 6】Sum square difference
- [Project Euler]加入欧拉 Problem 7
- [Project Euler]加入欧拉 Problem 15
- [Project Euler] Problem 11
- [Project Euler] Problem 25
- [Project Euler]Problem 7