4 "cell_type": "markdown",
7 "$\\sqrt{23} = 4 + \\sqrt{23} - 4 = \\frac{1}{\\frac{1}{\\sqrt{23}-4}}$\n",
9 "$\\frac{1}{\\sqrt{23}-4} = \\frac{\\sqrt{23}+4}{(\\sqrt{23}-4)(\\sqrt{23}+4)} = \\frac{\\sqrt{23}+4}{23 - 16}$\n",
13 "\\frac{1}{\\sqrt{23}-4} & = \\frac{\\sqrt{23}+4}{(\\sqrt{23}-4)(\\sqrt{23}+4)} \\\\\n",
14 " & =\\frac{\\sqrt{23}+4}{23 - 16} \\\\\n",
15 " & =\\frac{\\sqrt{23}+4}{7} , \\left \\lfloor \\frac{\\sqrt{23} + 4}{7} \\right \\rfloor = 1\\\\\n",
16 " & =1 + \\frac{\\sqrt{23} + 4 -7}{7} \\\\\n",
17 " & =1 + \\frac{\\sqrt{23} -3}{7} \\\\\n",
18 " & =1 + \\frac{\\sqrt{23} -3}{7} \n",
25 "1 + \\frac{\\sqrt{23} -3}{7} & = 1 + \\frac{1}{\\frac{7}{\\sqrt{23} -3}} \\\\\n",
26 "\\frac{7}{\\sqrt{23} -3} & =\\frac{7(\\sqrt{23}+3)}{(\\sqrt{23} -3)(\\sqrt{23}+3)}\\\\\n",
27 " & =\\frac{7(\\sqrt{23}+3)}{23 - 9} \\\\\n",
28 " & =\\frac{7(\\sqrt{23}+3)}{14}\\\\\n",
29 " & =\\frac{\\sqrt{23} + 3}{2}, \\left \\lfloor \\frac{\\sqrt{23} + 3}{2} \\right \\rfloor = 3\\\\\n",
30 " & = 3 + \\frac{\\sqrt{23} + 3}{2} - \\frac{6}{2}\\\\\n",
31 " & = 3 + \\frac{\\sqrt{23} - 3}{2}\\\\\n",
37 "\\frac{k}{\\sqrt{n} - a} \n",
38 " &= \\frac{k \\left( \\sqrt{n} + a \\right)}{\\left( \\sqrt{n} - a \\right) \\left( \\sqrt{n} + a \\right)} \\\\\n",
39 " & = \\frac{k \\left( \\sqrt{n} + a \\right)}{n - a^2} \\\\\n",
40 " & =\\left \\lfloor \\frac{k \\left( \\sqrt{n} + a \\right) }{n - a^2} \\right \\rfloor + \n",
41 " \\frac{k \\left( \\sqrt{n} + a \\right)}{n - a^2} - \\left \\lfloor \\frac{k \\left( \\sqrt{n} + a \\right) }{n - a^2} \\right \\rfloor \\\\\n",
42 " & =\\left \\lfloor \\frac{k \\left( \\sqrt{n} + a \\right) }{n - a^2} \\right \\rfloor + \n",
43 " \\frac{\\sqrt{n} + a}{\\frac{n - a^2}{k}} - \\left \\lfloor \\frac{k \\left( \\sqrt{n} + a \\right) }{n - a^2} \\right \\rfloor \\\\\n",
44 " & =\\left \\lfloor \\frac{k \\left( \\sqrt{n} + a \\right) }{n - a^2} \\right \\rfloor + \n",
45 " \\frac{\\sqrt{n} + a - \\left \\lfloor \\frac{k \\left( \\sqrt{n} + a \\right) }{n - a^2} \\right \\rfloor \\left( \\frac{n - a^2}{k} \\right)}{\\frac{n - a^2}{k}}\\\\\n",
46 " & = \\mathrm{lead} + \\frac{\\sqrt{n} + \\mathrm{trail}}{\\mathrm{denom}}\n",
64 "output_type": "execute_result"
68 "def continued(n, k, a)\n",
69 " lead = ((k * (Math.sqrt(n) + a)) / (n - a ** 2)).floor\n",
70 " denom = (n - a ** 2) / k\n",
71 " trail = a - lead * denom\n",
72 " [lead, denom, trail]\n",
89 "output_type": "execute_result"
93 "continued(23, 1, Math.sqrt(23).floor)"
107 "execution_count": 3,
109 "output_type": "execute_result"
113 "continued(23, 1, 4)"
118 "execution_count": 4,
127 "execution_count": 4,
129 "output_type": "execute_result"
133 "continued(23, 7, 3)"
138 "execution_count": 5,
147 "execution_count": 5,
149 "output_type": "execute_result"
153 "continued(23, 2, 3)"
158 "execution_count": 6,
167 "execution_count": 6,
169 "output_type": "execute_result"
173 "continued(23, 7, 4)"
178 "execution_count": 7,
187 "execution_count": 7,
189 "output_type": "execute_result"
193 "continued(23, 1, 4)"
198 "execution_count": 8,
207 "execution_count": 8,
209 "output_type": "execute_result"
213 "continued(23, 7, 3)"
218 "execution_count": 9,
227 "execution_count": 9,
229 "output_type": "execute_result"
233 "def continue_start(n)\n",
234 " continued(n, 1, Math.sqrt(n).floor)\n",
240 "execution_count": 10,
249 "execution_count": 10,
251 "output_type": "execute_result"
260 "execution_count": 11,
266 ":continue_until_repeat"
269 "execution_count": 11,
271 "output_type": "execute_result"
275 "def continue_until_repeat(n)\n",
276 " a_n = [Math.sqrt(n).floor]\n",
278 " l, d, t = continue_start(n)\n",
279 " while !states.include?([d, t])\n",
281 " states << [d, t]\n",
282 " l, d, t = continued(n, d, -1 * t)\n",
284 " [a_n, states, states.length - states.index([d, t])]\n",
290 "execution_count": 12,
296 "[[4, 1, 3, 1, 8], [[7, -3], [2, -3], [7, -4], [1, -4]], 4]"
299 "execution_count": 12,
301 "output_type": "execute_result"
305 "continue_until_repeat 23"
310 "execution_count": 13,
316 "[[3, 1, 1, 1, 1, 6], [[4, -1], [3, -2], [3, -1], [4, -3], [1, -3]], 5]"
319 "execution_count": 13,
321 "output_type": "execute_result"
325 "continue_until_repeat 13"
330 "execution_count": 14,
339 "execution_count": 14,
341 "output_type": "execute_result"
345 "Math.sqrt(8).floor ** 2"
350 "execution_count": 15,
356 ":repeat_period_length"
359 "execution_count": 15,
361 "output_type": "execute_result"
365 "def repeat_period_length(n)\n",
366 " a_n, states, period_length = continue_until_repeat(n)\n",
373 "execution_count": 19,
382 "execution_count": 19,
384 "output_type": "execute_result"
388 "repeat_period_length 13"
393 "execution_count": 20,
402 "execution_count": 20,
404 "output_type": "execute_result"
409 "(1..13).each do |i|\n",
410 " if (Math.sqrt(i).floor ** 2) != i\n",
411 " # puts \"#{i} -> #{repeat_period_length i}\"\n",
412 " odd_counts += 1 if repeat_period_length(i) % 2 == 1\n",
420 "execution_count": 21,
429 "execution_count": 21,
431 "output_type": "execute_result"
436 "(1..(10 ** 4)).each do |i|\n",
437 " if (Math.sqrt(i).floor ** 2) != i\n",
438 " # puts \"#{i} -> #{repeat_period_length i}\"\n",
439 " odd_counts += 1 if repeat_period_length(i) % 2 == 1\n",
447 "execution_count": null,
457 "display_name": "Ruby 2.4.0",
462 "file_extension": ".rb",
463 "mimetype": "application/x-ruby",