tijie
2024-10-12 16:36:32
发布于:天津
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
int a[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
LL cal(LL year) {
int start = -4712;
if (year < start) return 0;
LL res = (year - start + 1) * 365;
if (year < 1582) {
res += (year - start) / 4 + 1;
} else {
res -= 10;
res += (1581 - start)/4 + 1;
res += (year-1580)/4 - (year-1500)/100 +(year-1200)/400;
}
return res;
}
bool pd(int x) {
if (x > 1582) {
return (x % 4 == 0 && x % 100 != 0) || (x % 400 == 0);
} else {
return x % 4 == 0;
}
return 0;
}
int main(){
int Q;
scanf("%d", &Q);
while (Q--) {
LL n;
scanf("%lld", &n);
n++;
int l = -4712, r = 1e9 + 5;
while (l < r) {
int mid = (l + r )>> 1;
if (cal(mid) >= n) {
r = mid;
} else {
l = mid + 1;
}
}
n -= cal(l - 1);
a[2] = 28 + pd(l);
a[10] = l == 1582 ? 21 : 31;
int m;
for (int i = 1; i <= 12; i++) {
if (n > a[i]) {
n -= a[i];
} else {
m = i;
break;
}
}
if (l == 1582 && m == 10) {
if (n >= 5) n += 10;
printf("%lld %d %d\n", n, m, l);
} else {
if (l > 0)
printf("%lld %d %d\n", n, m, l);
else
printf("%lld %d %d BC\n", n, m, -(l-1));
}
}
return 0;
}
这里空空如也
有帮助,赞一个