Suppose we are working only in a period in which the leap years are those years, and only those years, that are divisible by four.
Given a number n, the number of positive numbers less than or equal to n that are multiples of four is floor(n/4). Let L(n) be this value, floor(n/4).
If we take a number m, the number of positive multiples of four up to m is L(m). When we subtract L(n), the result, L(m)−L(n), is the number of multiples of four greater than n but less than or equal to m.
Therefore, the number of leap years between year 1918 and year m is floor(m/4) − floor(1918/4) = floor(m/4) − 479. (If the base year were a leap year and we wanted to include it inside the period instead of outside, we could replace L(n) with L(n−1).
The above is easily extendable to the larger leap year pattern. By changing L(n) to floor(n/4) − floor(n/100) + floor(n/400), it becomes a count of positive numbers up to n that are multiples of four but are not multiples of 100 unless they are multiples of 400. Then L(m) − L(n) is the number of leap rules between n and m.
Thus a proper formula for the period covered by this rule is floor(n/4) − floor(n/100) + floor(n/400) − 464. Using C’s integer arithmetic, this is easily evaluated as n/4 - n/100 + n/400 - 464
.