-
Notifications
You must be signed in to change notification settings - Fork 0
/
formula.sf
33 lines (23 loc) · 1.24 KB
/
formula.sf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/ruby
# a(n) is the least k such that the denominators of continued fraction convergents for sqrt(k) match the first n Fibonacci numbers.
# https://oeis.org/A309666
# Let x = (F(n+1) + 1) / 2. Then a(n) = x^2 + (F(n-1) + 2*x*F(n))/F(n+1).
# More terms for A309666:
# 2, 3, 7, 7, 13, 58, 58, 135, 819, 819, 2081, 13834, 13834, 35955, 244647, 244647, 639389, 4374866, 4374866, 11448871, 78439683, 78439683, 205337953, 1407271538, 1407271538, 3684200835, 25251313255, 25251313255, 66108441037, 453111560266, 453111560266, 1186259960295, 8130736409715, 8130736409715, 21286537898177, 145900057560634, 145900057560634, 381971282645043, 2618069934304071, 2618069934304071, 6854195958519197, 46979357212148258, 46979357212148258, 122993553466365127, 843010353327929475, 843010353327929475, 2207029755827518273, 15127206974917077602, 15127206974917077602, 39603542006490489219
# See also:
# https://oeis.org/A309666
# https://oeis.org/A071296
var terms = Hash()
var nterms = 50
for n in (1..nterms) {
if (n % 3 == 2) {
next
}
var x = (fib(n+1) + 1)/2
var z = (x**2 + (fib(n-1) + 2*x*fib(n))/fib(n+1))
terms{n} := [] << z
terms{n+1} := [] << z
}
for n in (1..nterms) {
print(terms.has(n) ? terms{n}.min : '?', ", ")
}