[Project Euler]Problem 28
2012-09-27 21:40
387 查看
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?
解答:
这个值需要做个简单的观察,右上角对角线是N的平方。所以就很简单
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
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?
解答:
这个值需要做个简单的观察,右上角对角线是N的平方。所以就很简单
sum([4*i**2-6*i+6 for i in range(3, 103, 2)])+1
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
相关文章推荐
- [Project Euler] Problem 28
- Project Euler:Problem 28 Number spiral diagonals
- Project Euler:Problem 28 Number spiral diagonals
- Project Euler:Problem 86 Cuboid route
- Project Euler:Problem 16 Power digit sum
- Project Euler:Problem 30 Digit fifth powers
- Project Euler:Problem 36 Double-base palindromes
- Project Euler:Problem 44 Pentagon numbers
- Project Euler:Problem 46 Goldbach's other conjecture
- Project Euler – Problem 14
- Project Euler:Problem 68 Magic 5-gon ring
- Project Euler:Problem 85 Counting rectangles
- Project Euler:Problem 89 Roman numerals
- Project Euler:Problem 93 Arithmetic expressions
- Project Euler:Problem 39 Integer right triangles
- Project Euler__problem 2
- project euler 28
- java 求无限循环小数的循环体/循环部分 project euler problem26
- [Project Euler]加入欧拉 Problem 8
- [Project Euler] Problem 6