1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| #include<bits/stdc++.h> using namespace std; #define int long long const int mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; const int _1=365,_100=_1*100+24,_400=_100*4+1;
struct date{int y,m,d,ru;} t[4000010];
bool isrun(int year) { if(year<0) return (year+1)%4==0; return year%4==0&&(year<=1582||year%100!=0||year%400==0); } date nxtday(date a) { a.d++,a.ru++; if(a.y==1582&&a.m==10&&a.d==5) return a.d=15,a; if(a.m==2&&a.d==29&&isrun(a.y)); else if(a.d>mon[a.m]) a.m++,a.d=1; if(a.m>12) a.y++,a.y+=!a.y,a.m=1; return a; } void print(date x) { cout<<x.d<<" "<<x.m<<" "<<abs(x.y)<<(x.y<0?" BC":"")<<endl; } signed main() { t[0]={-4713,1,1,0}; int _20000101; for(int i=1;t[i-1].y<=2000;i++) { t[i]=nxtday(t[i-1]); if(t[i].y==2000&&t[i].m==1&&t[i].d==1) _20000101=t[i].ru; } int _0=_20000101-_400*5,T,x; cin>>T; while(T--) { cin>>x; if(x<=_20000101) print(t[x]); else { date ans{(x-_0)/_400*400,1,1,(x-_0)/_400*_400+_0}; while(ans.ru+_100+isrun(ans.y)<=x) ans.ru+=_100+isrun(ans.y),ans.y+=100; while(ans.ru+_1+isrun(ans.y)<=x) ans.ru+=_1+isrun(ans.y),ans.y++; while(ans.ru<x) ans=nxtday(ans); print(ans); } } return 0; }
|