#include <stdio.h>
#define COG1_TEETH 4
#define COG2_TEETH 25
#define COG3_TEETH 4
#define BASE 1584
/* BASE == (4 * COG1_TEETH * COG2_TEETH * COG3_TEETH - 16) */
int isleap(int year);
int main(void)
{
int year;
for (year = 1994; year < 2101; year++) {
printf("%d is %s\n", year,
isleap(year) ? "a leap year" : "not a leap year");
}
return 0;
}
int isleap(int year)
{
unsigned a, b, c;
unsigned i;
if (year < BASE) return 0; /* Not Gregorian year */
a = 0;
b = COG2_TEETH - COG1_TEETH;
c = COG3_TEETH - 1;
i = year - BASE;
while (i--) {
if (++a == COG1_TEETH) {
a = 0;
if (++b == COG2_TEETH) {
b = 0;
if (++c == COG3_TEETH)
c = 0;
}
}
}
return !b ? !a && !c : a == 0;
}