OFFSET
0,3
COMMENTS
Even-indexed terms are positive integers in order, with m occurring phi(m) times. Preceding odd-indexed terms (except for missing initial 0) are the corresponding numbers <= m and relatively prime to m, in increasing order. The denominators are just this sequence shifted left. Thus each positive rational occurs exactly once as a ratio a(n)/a(n+1). - Franklin T. Adams-Watters, Dec 06 2006
REFERENCES
H. Lauwerier, Fractals, Princeton Univ. Press, p. 23.
LINKS
EXAMPLE
First arrange fractions by increasing denominator, then by increasing numerator:
now follow each term (except the first) with its reciprocal:
MAPLE
with (numtheory): A038568 := 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 (j-1) fi: RETURN (k-1): end: # Ulrich Schimke (ulrschimke(AT)aol.com)
MATHEMATICA
a[n_] := Module[{sum = 1, k = 2}, While[sum < n, sum = sum + 2*EulerPhi[k]; k = k+1]; sum = sum - 2*EulerPhi[k-1]; j = 1; While[sum < n, If[GCD[j, k-1] == 1, sum = sum+2]; j = j+1; ]; If[sum > n, Return[j-1]]; Return[k-1] ]; Table[a[n], {n, 1, 100}] (* Jean-François Alcover, Nov 21 2012, translated from 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: return j - 1
return k - 1 # Indranil Ghosh, May 23 2017, translated from Mathematica
(Julia)
using Nemo
function A038568List(len)
a, A = QQ(0), []
for n in 1:len
a = next_minimal(a)
push!(A, numerator(a))
end
A end
A038568List(84) |> println # Peter Luschny, Mar 13 2018
(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 ([p, q][n+2]), n-=2))), n-=2*e)) } \\ Rémy Sigrist, Feb 25 2021
CROSSREFS
KEYWORD
nonn,frac,core,easy,nice
AUTHOR
EXTENSIONS
More terms from Erich Friedman
STATUS
approved