Leap years are determined by a scheme in which every $4$th year is a leap year, but every $4\cdot 25$th year is exempted, but every $4\cdot 25 \cdot 4$th year is reinstated $\ldots $ and there we stop, because that's good enough in practice to approximate the actual length of a year in terms of days. But what if we wanted to approximate arbitrarily well? In other words, can any real number $r$, $0<r<1$, be written in the form
$$
r=\sum\_{n=0}^{\infty} \frac{(-1)^n }{\prod\_{i=0}^{n} a\_i }
$$
with $a\_i $ a sequence of positive integers? For the earth at its current rate of rotation, where a fraction $r=0.242375$ of a day has to be represented, the existing sequence $a\_0 =4$, $a\_1 =25$, $a\_2 =4$ merely has to be supplemented by $a\_3 =20$ to reproduce this $r$ to the full known precision.



Leap year formula to arbitrary precision
The greedy algorithm always produces a suitable expansion. The proof follows.


**Lemma**: If $0<x<1$, then $x$ may be written as $\frac 1n(1-y)$ for some $n$ with $0\le y<\frac 1{n+1}$.


Proof: Let $n$ be such that $\frac 1{n+1}<x\le \frac 1n$. Then $0\le \frac 1n-x< \frac 1{n(n+1)}$. In particular, writing $y=n(\frac 1n-x)$, we see $0\le y<\frac 1{n+1}$ as required.


Note that in the above, $n=\lfloor \frac 1x\rfloor$ so that $y=\lfloor\frac 1x\rfloor (1/\lfloor \frac 1x\rfloor-x)=1-x\lfloor \frac 1x\rfloor$. Define the function $f(x)=\lfloor \frac 1x\rfloor$ and $g(x)=1-xf(x)$.


We now apply this inductively: let $x\_0=r$, and $x\_{n+1}=g(x\_n)$ for each $n$ and $a\_n=f(x\_n)$. We claim that for each $n$,
$$
r=\sum\_{j=0}^n \frac{(-1)^j}{\prod\_{i=0}^j a\_i}+\frac{(-1)^{n+1}}{\prod\_{i=0}^n a\_i}x\_{n+1}.
$$
Since $x\_{n+1}=\frac 1{a\_{n+1}}(1-x\_{n+2})$, the formula holds immediately by induction, proving the claim.


