First let's take our Leap Year system: a Leap Year is a year of 366 days, as opposed to normal years of 365 days. It occurs every 4 years, except if the year is divisible by 100, and not divisible by 400. The purpose of the system is to match the 365.241667 days of astronomical year as closely as possible, making astronomical New Year as close to "legal" New Year as possible.
Now, how would one generalize this problem?
So, we have a longer period $Y$ , composed of a fractional number ( $N_D$ ) of shorter periods $D$.
To generate the distribution we create two variants of the longer period $Y_l = ceil(N_D)$ and $Y_n = floor(N_D)$
Let's assume we known a certain there exist a pair l, n such that: $l \cdot Y_l + n \cdot Y_n \approx (l+n) Y$ with satisfactory precision.
Now, how to distribute $Y_l, Y_n$ most uniformly? How to make end of each consecutive year - normal or leap, our choice - to be least distant from the astronomical year? (specifically, not trying to minimize the sum of the differences, but the maximum possible difference)
Formally: a sequence $L_n$ is composed of $l+n$ 0's and 1's.
$$ \Delta = max \left|\left(\sum_{n=0}^x L_n \cdot Y_l + (1-L_n) \cdot Y_n \right) - x \cdot Y\right| \quad for\quad 0 \le x \le l+n$$
How to create the sequence $L_n$ that will create the smalest $\Delta$ ?
This is a question asking for answer for a very specific real-life problem: generating cycles of specific frequency, with base clock of a frequency which is not a divisor of the original frequency. Some pulses will be one clock cycle longer, some will be one cycle shorter, but I must match the original frequency as closely as possible (without being able to observe it for a time) and so I must be able to programmatically choose which cycles should be extended and which kept shorter than the original.
I think I came up with an answer that would allow me to come up with the decision process that allows picking the "leap years" on the run.
$$ S_i = \sum_{n=0}^i L_n \cdot Y_l + (1-L_n) \cdot Y_n $$
$$ L_{i} = \begin{cases}0 & iY - (S_{i-1} + Y_n) < (S_{i-1} + Y_l ) - iY \\ 1 & {otherwise} \end{cases} $$
In other words: use the one of the two - leap year/standard year, which for given year produces smaller difference respective to given astronomical year.