• Source
    1. #include<bits/stdc++.h>
    2. using namespace std;
    3.  
    4. string days(int y)
    5.  
    6. {
    7. int c=0,d;
    8. int i;
    9.  
    10. if(y>2001)
    11. {
    12. for(i=2001;i<y;i++)
    13. {
    14. if((i%4==0 &&i%100!=0)||i%400==0)
    15. c=c+2;
    16. else
    17. c++;
    18. }
    19. c=(1+(c%7))%7;
    20. }
    21. else
    22. {
    23. for(i=y;i<2001;i++)
    24. {
    25. if((i%4==0 &&i%100!=0)||i%400==0)
    26. c+=2;
    27. else
    28. c++;
    29. }
    30. c=(8-(c%7))%7;
    31. }
    32. string st="";
    33. if(c==2)
    34. st += "tuesday";
    35. if(c==3)
    36. st += "wednesday";
    37. if(c==4)
    38. st += "thursday";
    39. if(c==5)
    40. st += "friday";
    41. if(c==6)
    42. st += "saturday";
    43. if(c==0)
    44. st += "sunday";
    45. if(c==1)
    46. st += "monday";
    47. return st;
    48.  
    49. }
    50.  
    51. int main()
    52. {
    53. // MAIN FORMULA - (year code + month code + century code + Date number - Leap year code)%7
    54. // Here as Date is 1 & Month is January hence DATE NUMBER is 1 and MONTH CODE is 0
    55. // If leap year SUBSTRACT 1 ELSE DON'T
    56. // Year code formula - (YY +(YY/4))%7 where in 1898 YY is 98
    57. // Century code - 1800s - 2; 1900s - 0; 2000s - 6; 2100s - 4; 2200s - 2; 2300s - 0;
    58. int number_of_years, year_code, month_code, yy, century_code, date_number, leap_year, year[1000], day, i, j;
    59. month_code = 0;
    60. date_number = 1;
    61. //scanf("%d",&number_of_years);
    62. for(i = 1800; i<=2600; i++)
    63. {
    64. //printf(" * ");
    65. year[i-1900] = i;
    66. }
    67.  
    68. for(j = 0; j<=700; j++)
    69. {
    70. year[j] = j+1800;
    71. yy = 0; century_code = 0; year_code = 0; leap_year = 0; day = 0;
    72. {
    73. if(year[j]>=1800 && year[j]<=1899)
    74. {century_code = 2; yy = year[j] - 1800; year_code = ((yy+(yy/4))%7);}
    75. else if(year[j]>=1900 && year[j]<=1999)
    76. {century_code = 0; yy = year[j] - 1900; year_code = ((yy+(yy/4))%7);}
    77. else if(year[j]>=2000 && year[j]<=2099)
    78. {century_code = 6; yy = year[j] - 2000; year_code = ((yy+(yy/4))%7);}
    79. else if(year[j]>=2100 && year[j]<=2199)
    80. {century_code = 4; yy = year[j] - 2100; year_code = ((yy+(yy/4))%7);}
    81. else if(year[j]>=2200 && year[j]<=2299)
    82. {century_code = 2; yy = year[j] - 2200; year_code = ((yy+(yy/4))%7);}
    83. else if(year[j]>=2300 && year[j]<=2399)
    84. {century_code = 0; yy = year[j] - 2300; year_code = ((yy+(yy/4))%7);}
    85. else if(year[j]>=2400 && year[j]<=2499)
    86. {century_code = 6; yy = year[j] - 2400; year_code = ((yy+(yy/4))%7);}
    87. else if(year[j]>=2500 && year[j]<=2599)
    88. {century_code = 4; yy = year[j] - 2500; year_code = ((yy+(yy/4))%7);}
    89. }
    90. if((year[j]%4 == 0) && (year[j]%100 != 0))
    91. { leap_year = 1;}
    92. else if(year[j]%400 == 0)
    93. { leap_year = 1;}
    94.  
    95. day = ((year_code + month_code + century_code + date_number - leap_year)%7);
    96. string st="";
    97. switch(day)
    98. { case 0: st = "sunday";
    99. break ;
    100. case 1: st += "monday";
    101. break ;
    102. case 2: st += "tuesday";
    103. break ;
    104. case 3: st += "wednesday";
    105. break ;
    106. case 4: st += "thursday";
    107. break ;
    108. case 5: st += "friday" ;
    109. break ;
    110. case 6: st += "saturday";
    111. break ;
    112. }
    113. string temp = days(year[j]);
    114. //printf("*");
    115. if(st != temp){
    116. printf("%d\n",year[j]);
    117. }
    118. }
    119.  
    120.  
    121. return 0;
    122. }