Problem 6
- 投稿者 : rei
Original
The sum of the squares of the first ten natural numbers is,
1² + 2² + … + 10² = 385
The square of the sum of the first ten natural numbers is,(1 + 2 + … + 10)² = 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.
和訳
最初の10個の自然数について、その和の二乗と、二乗数の和は以下の通り。
1² + 2² + … + 10² = 385
(1 + 2 + … + 10)² = 3025
これらの数の差は 3025 – 385 = 2640 となる。同様にして、最初の100個の自然数について和の二乗と二乗の和の差を求めよ。
当てにならないソースコード(C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | using System; namespace ProjectEuler { class Problem6 { public Problem6() { int a = 0, b = 0; Console.WriteLine(this.ToString()); for (int i = 1; i <= 100; i++) { a += i; b += i * i; } Console.WriteLine("> " + (a * a - b)); } } } |
ん?

rei@sikios.com
コメントはまだありません。