Files
freeCodeCamp/curriculum/challenges/chinese/10-coding-interview-prep/project-euler/problem-28-number-spiral-diagonals.md

54 lines
844 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
id: 5900f3881000cf542c50fe9b
title: 问题28对角螺旋数
challengeType: 5
videoUrl: ''
---
# --description--
从数字1开始沿顺时针方向向右移动形成5 x 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。
以相同方式形成的n×n螺旋中的对角线上的数字的总和是多少
# --hints--
`spiralDiagonals(101)`应该返回692101。
```js
assert(spiralDiagonals(101) == 692101);
```
`spiralDiagonals(101)`应该返回18591725。
```js
assert(spiralDiagonals(303) == 18591725);
```
`spiralDiagonals(101)`应该返回85986601。
```js
assert(spiralDiagonals(505) == 85986601);
```
`spiralDiagonals(101)`应该返回669171001。
```js
assert(spiralDiagonals(1001) == 669171001);
```
# --solutions--