OFFSET
0,2
COMMENTS
See A020652/A020653 for an alternative version where the fractions p/q are listed by increasing p+q, then p. - M. F. Hasler, Nov 25 2021
REFERENCES
H. Lauwerier, Fractals, Princeton Univ. Press, p. 23.
LINKS
EXAMPLE
First arrange the positive fractions p/q <= 1 by increasing denominator, then by increasing numerator:
Now follow each but the first term by its reciprocal:
MAPLE
with (numtheory): A038569 := proc (n) local sum, j, k; sum := 1: k := 2: while (sum < n) do: sum := sum + 2 * phi(k): k := k + 1: od: sum := sum - 2 * phi(k-1): j := 1: while sum < n do: if gcd(j, k-1) = 1 then sum := sum + 2: fi: j := j+1: od: if sum > n then RETURN (k-1) fi: RETURN (j-1): end: # Ulrich Schimke (ulrschimke(AT)aol.com)
MATHEMATICA
a[n_] := Module[{s = 1, k = 2, j = 1}, While[s <= n, s = s + 2*EulerPhi[k]; k = k+1]; s = s - 2*EulerPhi[k-1]; While[s <= n, If[GCD[j, k-1] == 1, s = s+2]; j = j+1]; If[s > n+1, k-1, j-1]]; Table[a[n], {n, 0, 99}](* Jean-François Alcover, Nov 10 2011, after Maple *)
PROG
(Python)
from sympy import totient, gcd
def a(n):
s=1
k=2
while s<=n:
s+=2*totient(k)
k+=1
s-=2*totient(k - 1)
j=1
while s<=n:
if gcd(j, k - 1)==1: s+=2
j+=1
if s>n + 1: return k - 1
return j - 1 # Indranil Ghosh, May 23 2017, translated from Mathematica
(PARI) a(n) = { my (e); for (q=1, oo, if (n+1<2*e=eulerphi(q), for (p=1, oo, if (gcd(p, q)==1, if (n+1<2, return ([q, p][n+2]), n-=2))), n-=2*e)) } \\ Rémy Sigrist, Feb 25 2021
CROSSREFS
KEYWORD
nonn,frac,core,nice
AUTHOR
EXTENSIONS
More terms from Erich Friedman
Definition clarified by N. J. A. Sloane, Nov 25 2021
STATUS
approved