login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A160520
a(n) is the number of distinct values in the periodic part of the continued fraction of the square root of n-th nonsquare positive integer.
1
1, 2, 1, 2, 2, 2, 1, 2, 2, 2, 3, 2, 1, 2, 4, 2, 3, 4, 3, 2, 1, 2, 3, 3, 2, 4, 2, 3, 3, 2, 1, 2, 2, 2, 2, 2, 4, 3, 3, 5, 3, 2, 1, 2, 4, 3, 4, 2, 2, 3, 2, 4, 3, 5, 3, 2, 1, 2, 5, 2, 4, 3, 4, 2, 3, 2, 2, 5, 4, 3, 3, 2, 1, 2, 2
OFFSET
1,2
EXAMPLE
The 10th nonsquare positive integer is 13; sqrt(13) = cf[3;(1,1,1,1,6)], which has period 5, and 2 distinct values in its periodic part.
MATHEMATICA
Length@Union@Last@ContinuedFraction@Sqrt@#&/@Select[Range@100, !IntegerQ@Sqrt@#&] (* Giorgos Kalogeropoulos, May 05 2022 *)
PROG
(Python)
import math
def findperiod( d ) :
if len(d) == 0 :
return 0
for p in range( 1, len(d) - 1 ) :
isPeriod = True
for i in range(0, p) :
for j in range(i + p, len(d), p ) :
if not d[i] == d[j] :
isPeriod = False
break
if not isPeriod :
break
if isPeriod :
return len( set( d[:p] ) )
return -1
def nextv( a, b, n, less = True ) :
# print a, b, a[1]*a[1], n * a[0] * a[0]
d = -1
while (a[1]*a[1] < n * a[0] * a[0]) == less :
d += 1
a = ( a[0] + b[0], a[1] + b[1] )
a = ( a[0] - b[0], a[1] - b[1] )
return d, a, b
def generated( n ) :
maxperiod = 100
s = int( math.sqrt( n ) )
if s * s == n :
return []
a = (1, 0)
b = (0, 1)
ds = []
for i in range( maxperiod ):
d, b, a = nextv( a, b, n )
ds.append( d )
d, b, a = nextv( a, b, n, less = False )
ds.append( d )
return ds[1:]
maxn = 1000
ns = [x for x in range( maxn ) if not int( math.sqrt( x ) ) ** 2 == x ]
v = list(map( findperiod, map( generated, ns ) ))
if v.count( -1 ) == 0 :
print(v)
(Python)
from math import isqrt
from sympy.ntheory.continued_fraction import continued_fraction_periodic
def A160520(n): return len(set(continued_fraction_periodic(0, 1, n+(k:=isqrt(n))+int(n>=k*(k+1)+1))[-1])) # Chai Wah Wu, Jul 20 2024
CROSSREFS
Sequence in context: A092505 A066086 A323406 * A235708 A353929 A297770
KEYWORD
nonn
AUTHOR
Dremov Dmitry (dremovd(AT)gmail.com), May 16 2009
STATUS
approved