Problem 28
- 投稿者 : rei
Original
Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:
21 22 23 24 25 20 7 8 9 10 19 6 1 2 11 18 5 4 3 12 17 16 15 14 13 It can be verified that the sum of the numbers on the diagonals is 101.
What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way?
和訳
1から初めて右方向に進み時計回りに数字を増やしていき、
5×5の螺旋が以下のように生成される:
21 22 23 24 25 20 7 8 9 10 19 6 1 2 11 18 5 4 3 12 17 16 15 14 13 両対角線上の数字の合計は101であることが確かめられる。
1001×1001の螺旋を同じ方法で生成したとき、対角線上の数字の合計はいくつだろうか?
当てにならないソースコード(C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | using System; namespace ProjectEuler { class Problem28 : Problem{ public Problem28() { int sum = 1, rb = 1, rt = 1, x; for (int i = 2; 2 * i - 1 <= 1001; i++) { x = (i - 1) * 2; rb = rt + x; rt = (x + 1) * (x + 1); sum += 2 * (rb + rt); } Console.WriteLine("> " + sum); } } } |
こういうパズル系の問題は好きです。

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