2018-09-30 23:01:58 +01:00
---
id: 5900f3ac1000cf542c50febf
challengeType: 5
title: 'Problem 64: Odd period square roots'
2019-08-05 09:17:33 -07:00
forumTopicId: 302176
2018-09-30 23:01:58 +01:00
---
## Description
< section id = 'description' >
2020-02-28 21:39:47 +09:00
All square roots are periodic when written as continued fractions and can be written in the form:
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\displaystyle \quad \quad \sqrt{N}=a_0+\frac 1 {a_1+\frac 1 {a_2+ \frac 1 {a3+ \dots}}}$
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
For example, let us consider $\sqrt{23}:$:
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\quad \quad \sqrt{23}=4+\sqrt{23}-4=4+\frac 1 {\frac 1 {\sqrt{23}-4}}=4+\frac 1 {1+\frac{\sqrt{23}-3}7}$
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
If we continue we would get the following expansion:
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\displaystyle \quad \quad \sqrt{23}=4+\frac 1 {1+\frac 1 {3+ \frac 1 {1+\frac 1 {8+ \dots}}}}$
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
The process can be summarized as follows:
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\quad \quad a_0=4, \frac 1 {\sqrt{23}-4}=\frac {\sqrt{23}+4} 7=1+\frac {\sqrt{23}-3} 7$
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\quad \quad a_1=1, \frac 7 {\sqrt{23}-3}=\frac {7(\sqrt{23}+3)} {14}=3+\frac {\sqrt{23}-3} 2$
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\quad \quad a_2=3, \frac 2 {\sqrt{23}-3}=\frac {2(\sqrt{23}+3)} {14}=1+\frac {\sqrt{23}-4} 7$
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\quad \quad a_3=1, \frac 7 {\sqrt{23}-4}=\frac {7(\sqrt{23}+4)} 7=8+\sqrt{23}-4$
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\quad \quad a_4=8, \frac 1 {\sqrt{23}-4}=\frac {\sqrt{23}+4} 7=1+\frac {\sqrt{23}-3} 7$
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\quad \quad a_5=1, \frac 7 {\sqrt{23}-3}=\frac {7 (\sqrt{23}+3)} {14}=3+\frac {\sqrt{23}-3} 2$
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\quad \quad a_6=3, \frac 2 {\sqrt{23}-3}=\frac {2(\sqrt{23}+3)} {14}=1+\frac {\sqrt{23}-4} 7$
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\quad \quad a_7=1, \frac 7 {\sqrt{23}-4}=\frac {7(\sqrt{23}+4)} {7}=8+\sqrt{23}-4$
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
It can be seen that the sequence is repeating. For conciseness, we use the notation $\sqrt{23}=[4;(1,3,1,8)]$, to indicate that the block (1,3,1,8) repeats indefinitely.
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
The first ten continued fraction representations of (irrational) square roots are:
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\quad \quad \sqrt{2}=[1;(2)]$, period = 1
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\quad \quad \sqrt{3}=[1;(1,2)]$, period = 2
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\quad \quad \sqrt{5}=[2;(4)]$, period = 1
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\quad \quad \sqrt{6}=[2;(2,4)]$, period = 2
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\quad \quad \sqrt{7}=[2;(1,1,1,4)]$, period = 4
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\quad \quad \sqrt{8}=[2;(1,4)]$, period = 2
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\quad \quad \sqrt{10}=[3;(6)]$, period = 1
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\quad \quad \sqrt{11}=[3;(3,6)]$, period = 2
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\quad \quad \sqrt{12}=[3;(2,6)]$, period = 2
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
$\quad \quad \sqrt{13}=[3;(1,1,1,1,6)]$, period = 5
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
Exactly four continued fractions, for $N \le 13$, have an odd period.
2018-09-30 23:01:58 +01:00
2020-02-28 21:39:47 +09:00
How many continued fractions for $N \le 10\,000$ have an odd period?
2018-09-30 23:01:58 +01:00
< / section >
## Instructions
< section id = 'instructions' >
< / section >
## Tests
< section id = 'tests' >
```yml
2018-10-04 14:37:37 +01:00
tests:
2020-02-28 21:39:47 +09:00
- text: < code > oddPeriodSqrts()</ code > should return a number.
testString: assert(typeof oddPeriodSqrts() === 'number');
- text: < code > oddPeriodSqrts()</ code > should return 1322.
testString: assert.strictEqual(oddPeriodSqrts(), 1322);
2018-09-30 23:01:58 +01:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
2020-02-28 21:39:47 +09:00
function oddPeriodSqrts() {
2020-09-15 09:57:40 -07:00
2018-09-30 23:01:58 +01:00
return true;
}
2020-02-28 21:39:47 +09:00
oddPeriodSqrts();
2018-09-30 23:01:58 +01:00
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
// solution required
```
2019-07-18 08:24:12 -07:00
2018-09-30 23:01:58 +01:00
< / section >