fork download
  1. #include <stdio.h>
  2.  
  3. #define COG1_TEETH 4
  4. #define COG2_TEETH 25
  5. #define COG3_TEETH 4
  6. #define BASE 1584
  7. /* BASE == (4 * COG1_TEETH * COG2_TEETH * COG3_TEETH - 16) */
  8.  
  9. int isleap(int year);
  10.  
  11. int main(void)
  12. {
  13. int year;
  14.  
  15. for (year = 1994; year < 2101; year++) {
  16. printf("%d is %s\n", year,
  17. isleap(year) ? "a leap year" : "not a leap year");
  18. }
  19.  
  20. return 0;
  21. }
  22.  
  23. int isleap(int year)
  24. {
  25. unsigned a, b, c;
  26. unsigned i;
  27.  
  28. if (year < BASE) return 0; /* Not Gregorian year */
  29.  
  30. a = 0;
  31. b = COG2_TEETH - COG1_TEETH;
  32. c = COG3_TEETH - 1;
  33. i = year - BASE;
  34.  
  35. while (i--) {
  36. if (++a == COG1_TEETH) {
  37. a = 0;
  38. if (++b == COG2_TEETH) {
  39. b = 0;
  40. if (++c == COG3_TEETH)
  41. c = 0;
  42. }
  43. }
  44. }
  45.  
  46. return !b ? !a && !c : a == 0;
  47. }
  48.  
Success #stdin #stdout 0s 2008KB
stdin
Standard input is empty
stdout
1994 is not a leap year
1995 is not a leap year
1996 is a leap year
1997 is not a leap year
1998 is not a leap year
1999 is not a leap year
2000 is a leap year
2001 is not a leap year
2002 is not a leap year
2003 is not a leap year
2004 is a leap year
2005 is not a leap year
2006 is not a leap year
2007 is not a leap year
2008 is a leap year
2009 is not a leap year
2010 is not a leap year
2011 is not a leap year
2012 is a leap year
2013 is not a leap year
2014 is not a leap year
2015 is not a leap year
2016 is a leap year
2017 is not a leap year
2018 is not a leap year
2019 is not a leap year
2020 is a leap year
2021 is not a leap year
2022 is not a leap year
2023 is not a leap year
2024 is a leap year
2025 is not a leap year
2026 is not a leap year
2027 is not a leap year
2028 is a leap year
2029 is not a leap year
2030 is not a leap year
2031 is not a leap year
2032 is a leap year
2033 is not a leap year
2034 is not a leap year
2035 is not a leap year
2036 is a leap year
2037 is not a leap year
2038 is not a leap year
2039 is not a leap year
2040 is a leap year
2041 is not a leap year
2042 is not a leap year
2043 is not a leap year
2044 is a leap year
2045 is not a leap year
2046 is not a leap year
2047 is not a leap year
2048 is a leap year
2049 is not a leap year
2050 is not a leap year
2051 is not a leap year
2052 is a leap year
2053 is not a leap year
2054 is not a leap year
2055 is not a leap year
2056 is a leap year
2057 is not a leap year
2058 is not a leap year
2059 is not a leap year
2060 is a leap year
2061 is not a leap year
2062 is not a leap year
2063 is not a leap year
2064 is a leap year
2065 is not a leap year
2066 is not a leap year
2067 is not a leap year
2068 is a leap year
2069 is not a leap year
2070 is not a leap year
2071 is not a leap year
2072 is a leap year
2073 is not a leap year
2074 is not a leap year
2075 is not a leap year
2076 is a leap year
2077 is not a leap year
2078 is not a leap year
2079 is not a leap year
2080 is a leap year
2081 is not a leap year
2082 is not a leap year
2083 is not a leap year
2084 is a leap year
2085 is not a leap year
2086 is not a leap year
2087 is not a leap year
2088 is a leap year
2089 is not a leap year
2090 is not a leap year
2091 is not a leap year
2092 is a leap year
2093 is not a leap year
2094 is not a leap year
2095 is not a leap year
2096 is a leap year
2097 is not a leap year
2098 is not a leap year
2099 is not a leap year
2100 is not a leap year