This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A160520 #20 Jul 20 2024 15:33:53 %S A160520 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, %T A160520 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, %U A160520 4,3,3,2,1,2,2 %N 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. %e A160520 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. %t A160520 Length@Union@Last@ContinuedFraction@Sqrt@#&/@Select[Range@100,!IntegerQ@Sqrt@#&] (* _Giorgos Kalogeropoulos_, May 05 2022 *) %o A160520 (Python) %o A160520 import math %o A160520 def findperiod( d ) : %o A160520 if len(d) == 0 : %o A160520 return 0 %o A160520 for p in range( 1, len(d) - 1 ) : %o A160520 isPeriod = True %o A160520 for i in range(0, p) : %o A160520 for j in range(i + p, len(d), p ) : %o A160520 if not d[i] == d[j] : %o A160520 isPeriod = False %o A160520 break %o A160520 if not isPeriod : %o A160520 break %o A160520 if isPeriod : %o A160520 return len( set( d[:p] ) ) %o A160520 return -1 %o A160520 def nextv( a, b, n, less = True ) : %o A160520 # print a, b, a[1]*a[1], n * a[0] * a[0] %o A160520 d = -1 %o A160520 while (a[1]*a[1] < n * a[0] * a[0]) == less : %o A160520 d += 1 %o A160520 a = ( a[0] + b[0], a[1] + b[1] ) %o A160520 a = ( a[0] - b[0], a[1] - b[1] ) %o A160520 return d, a, b %o A160520 def generated( n ) : %o A160520 maxperiod = 100 %o A160520 s = int( math.sqrt( n ) ) %o A160520 if s * s == n : %o A160520 return [] %o A160520 a = (1, 0) %o A160520 b = (0, 1) %o A160520 ds = [] %o A160520 for i in range( maxperiod ): %o A160520 d, b, a = nextv( a, b, n ) %o A160520 ds.append( d ) %o A160520 d, b, a = nextv( a, b, n, less = False ) %o A160520 ds.append( d ) %o A160520 return ds[1:] %o A160520 maxn = 1000 %o A160520 ns = [x for x in range( maxn ) if not int( math.sqrt( x ) ) ** 2 == x ] %o A160520 v = list(map( findperiod, map( generated, ns ) )) %o A160520 if v.count( -1 ) == 0 : %o A160520 print(v) %o A160520 (Python) %o A160520 from math import isqrt %o A160520 from sympy.ntheory.continued_fraction import continued_fraction_periodic %o A160520 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 %Y A160520 Cf. A013943, A099725. %K A160520 nonn %O A160520 1,2 %A A160520 Dremov Dmitry (dremovd(AT)gmail.com), May 16 2009