AC_Code:
1 //400年一循环+蔡勒公式 2 #include <bits/stdc++.h> 3 using namespace std; 4 typedef long long ll; 5 const int maxn = 1e5+10; 6 const ll inf=1e18; 7 const ll mod=1e9+7; 8 #define rep(i,first,last) for(int i=first;i<=last;i++) 9 #define dep(i,first,last) for(int i=first;i>=last;i--) 10 11 int y,m,d,n; 12 int rm[13]={0,31,29,31,30,31,30,31,31,30,31,30,31}; 13 int brm[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 14 bool run(int k){//判断闰平年 15 if( k%400==0 ) return true; 16 else if( k%100!=0 && k%4==0 ) return true; 17 else return false; 18 } 19 20 //蔡勒公式,计算这一天是周几,公式只适用于1582年10月15日之后的情形 21 char weekday[10][10]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}; 22 int zeller(int year,int month,int day){ 23 int m,d=day; 24 if( month<3 ){ 25 m=month+12; 26 year--; 27 } 28 else m=month; 29 int c=year/100; 30 int y=year%100; 31 int w=(c/4)-2*c+(y+y/4)+(26*(m+1)/10)+d-1; 32 return (w%7+7)%7; //返回0代表周日 33 } 34 35 int cnt[15]; 36 int ret[15]; 37 int a,b; 38 int main() 39 { 40 scanf("%d%d",&a,&b); 41 rep(i,a,a+399){ 42 int ans=0; 43 rep(j,1,12){ 44 if( zeller(i,j,13)==5 ){ 45 ans++; 46 } 47 } 48 cnt[ans]++; 49 } 50 51 int num=(b-a)/400; 52 rep(i,0,12){ 53 ret[i]=cnt[i]*(num); 54 } 55 int kiss=a+num*400; 56 rep(i,kiss,b){ 57 int ans=0; 58 rep(j,1,12){ 59 if( zeller(i,j,13)==5 ){ 60 ans++; 61 } 62 } 63 ret[ans]++; 64 } 65 rep(i,0,12){ 66 printf("%d: %d ",i,ret[i]); 67 } 68 return 0; 69 }