freeCodeCamp/curriculum/challenges/chinese/10-coding-interview-prep/project-euler/problem-64-odd-period-squar...

91 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
id: 5900f3ac1000cf542c50febf
title: 问题64奇数期平方根
challengeType: 5
videoUrl: ''
dashedName: problem-64-odd-period-square-roots
---
# --description--
所有平方根都是周期性的,当写为连续分数时,可以写成以下形式:
√N= a0 + 1
a1 + 1
a2 + 1
a3 + ......
例如让我们考虑√23
√23= 4 +√23 - 4 = 4 + 1 = 4 + 1
1√23-4
1 +√23 - 37
如果我们继续,我们将得到以下扩展:
√23= 4 + 1
1 + 1
3 + 1
1 + 1
8 + ......
该过程可归纳如下:
a0 = 4
1√23-4=√23+ 47 = 1 +√23-37a1 = 1
7√23-3= 7√23+ 314 = 3 +√23-32a2= 3
2√23-3= 2√23+ 314 = 1 +√23-47a3 = 1
7√23-4= 7√23+ 47 = 8 +√23-4a4= 8
1√23-4=√23+ 47 = 1 +√23-37a5 = 1
7√23-3= 7√23+ 314 = 3 +√23-32a6= 3
2√23-3= 2√23+ 314 = 1 +√23-47a7 = 1
7√23-4= 7√23+ 47 = 8 +√23-4
可以看出序列是重复的。为简明起见我们使用符号√23= \[4;1,3,1,8]来表示块1,3,1,8无限重复。
无理平方根的前十个连续分数表示为√2= \[1;2],周期=1√3= \[1;1,2],周期=2√5= \[2; 4],期间=1√6= \[2;2,4],期间=2√7= \[2;1,1,1,4],期间=4√8= \[2; 1,4],期间=2√10= \[3;6],期间=1√11= \[3;3,6],期间=2√12= \[3;2,6 ]period =2√13= \[3;1,1,1,1,6]period = 5对于N≤13恰好四个连续分数具有奇数周期。 N≤10000的连续分数有多少个奇数周期
# --hints--
`euler64()`应返回1322。
```js
assert.strictEqual(euler64(), 1322);
```
# --seed--
## --seed-contents--
```js
function oddPeriodSqrts() {
return true;
}
oddPeriodSqrts();
```
# --solutions--
```js
// solution required
```