# [seqfan] first occurrence in c.f. of Pi

Olivier Gerard ogerard at ext.jussieu.fr
Sat Apr 11 00:48:50 CEST 1998

```At 15:53 +0200 98.04.10, N. J. A. Sloane wrote:
> a sequence that i don't have:
> a(n) = first occurrence of n as a term in the
> continued fraction for Pi.
> It seems to begin 4,9,1,30,40,...
> Can someone please compute it?

Dr Wouter Meeussen has calculated it by now. I post it as he
sent it to me, as he was temporarily unable to post it directly:

> on popular demand:
> The Continued Fraction representation of;
> Where does n (=1,2,3,...,89) occur the first time?
>
> {4,9,1,30,40,32,2,44,130,100,276,55,28,13,3,78,647,137,140,180,214,83,203,91,
>   791,112,574,175,243,147,878,455,531,421,1008,594,784,3041,721,1872,754,119,
>   492,429,81,3200,825,283,3027,465,1437,3384,1547,1864,446,1018,135,362,907,
>   1127,868,884,1249,5606,964,9721,1789,7339,7146,2855,9215,510,898,3754,4634,
>   6186,5494,4908,6222,1579,5265,4655,9131,22,3251,1252,3276,1223,4829}
>
>
> Method:
>
> In[1]:=<<NumberTheory`ContinuedFractions`
> In[4]:=it=ContinuedFraction[Pi,10000]//First; (* about 4h on a 90MHz Machine *)
> In[5]:=Complement[Range[200],Union[it]]
> Out[5]=
> {90,91,96,103,109,110,115,122,126,128,131,132,133,135,136,139,140,145,147,149,
>   150,151,153,158,159,160,163,165,168,169,170,171,173,174,175,177,179,181,182,
>   183,184,185,187,189,190,191,192,194,195,197,198,199,200}
> In[6]:=Flatten[First[Position[it,#]]&/@Range[89] ]
> Out[6]=
> {4,9,1,30,40,32,2,44,130,100,276,55,28,13,3,78,647,137,140,180,214,83,203,91,
>   791,112,574,175,243,147,878,455,531,421,1008,594,784,3041,721,1872,754,119,
>   492,429,81,3200,825,283,3027,465,1437,3384,1547,1864,446,1018,135,362,907,
>   1127,868,884,1249,5606,964,9721,1789,7339,7146,2855,9215,510,898,3754,4634,
>   6186,5494,4908,6222,1579,5265,4655,9131,22,3251,1252,3276,1223,4829}
> In[7]:=it[[%]]==Range[89]
> Out[7]=True
>
> Dr. Wouter L. J. MEEUSSEN
> w.meeussen.vdmcc at vandemoortele.be
> eu000949 at pophost.eunet.be
>

A little remark on Mathematica programming. The code for
compiling the sequence:

Flatten[First[Position[it,#]]&/@Range[89] ]

could have been more efficiently written

Flatten[Position[it,#,1,1]&/@Range[89] ]

this way the Position function stops at the first occurrence
(on the first level of depth) of the pattern searched.

I believe that other similar sequences for numbers having an
irregularly distributed c.f. could be interesting.
For instance, this one is not (yet) in the table

1 15 2 7 4 64 56 10 59 14 148 18 117 12 32 638 ....

(Can you guess which one it is ?)

Olivier