#include <stdio.h>
#define COG1_TEETH 4
#define COG2_TEETH 25
#define COG3_TEETH 4
#define BASE (4 * COG1_TEETH * COG2_TEETH * COG3_TEETH - 16)
int isleap(int year);
int main(void)
{
int year = 2100;
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;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiAKI2RlZmluZSBDT0cxX1RFRVRIICAgIDQKI2RlZmluZSBDT0cyX1RFRVRIICAgIDI1CiNkZWZpbmUgQ09HM19URUVUSCAgICA0CiNkZWZpbmUgQkFTRSAoNCAqIENPRzFfVEVFVEggKiBDT0cyX1RFRVRIICogQ09HM19URUVUSCAtIDE2KQogIAppbnQgaXNsZWFwKGludCB5ZWFyKTsKIAppbnQgbWFpbih2b2lkKQp7CglpbnQgeWVhciA9IDIxMDA7CgkKCXByaW50ZigiJWQgaXMgJXNcbiIsIHllYXIsIGlzbGVhcCh5ZWFyKSA/ICJhIGxlYXAgeWVhciIgOiAibm90IGEgbGVhcCB5ZWFyIik7CiAgICAKICAgIHJldHVybiAwOwp9CiAgCmludCBpc2xlYXAoaW50IHllYXIpCnsKICAgIHVuc2lnbmVkIGEsIGIsIGM7CiAgICB1bnNpZ25lZCBpOwogICAgICAgICAKICAgIGlmICh5ZWFyIDwgQkFTRSkgcmV0dXJuIDA7ICAgICAgLyogTm90IEdyZWdvcmlhbiB5ZWFyICovCiAgICAgCiAgICBhID0gMDsKICAgIGIgPSBDT0cyX1RFRVRIIC0gQ09HMV9URUVUSDsKICAgIGMgPSBDT0czX1RFRVRIIC0gMTsKICAgIGkgPSB5ZWFyIC0gQkFTRTsKICAgICAKICAgIHdoaWxlIChpLS0pIHsKICAgICAgICBpZiAoKythID09IENPRzFfVEVFVEgpIHsKICAgICAgICAgICAgYSA9IDA7CiAgICAgICAgICAgIGlmICgrK2IgPT0gQ09HMl9URUVUSCkgewogICAgICAgICAgICAgICAgYiA9IDA7CiAgICAgICAgICAgICAgICBpZiAoKytjID09IENPRzNfVEVFVEgpCiAgICAgICAgICAgICAgICAgICAgYyA9IDA7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgCiAgICByZXR1cm4gIWIgPyAhYSAmJiAhYyA6IGEgPT0gMDsKfQo=