http://acm.hdu.edu.cn/showproblem.php?pid=4551
- 题解,暴力跑完366天每天的最大公约数和最小公倍数
- 一个个对比
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int t, a, b, year;
struct node{
int gcd;
int lcm;
}arr[50][50];
int judge(int y){
if(y%400==0 || (y%100!=0 && y%4==0))return 1;
return 0;
}
int day[30] = {0,31,29,31,30,31,30,31,31,30,31,30,31};
void init(){
for(int i = 1; i <= 12; i ++){
for(int j = 1; j <= 31; j ++){
arr[i][j].gcd = __gcd(i, j);
arr[i][j].lcm = i*j/arr[i][j].gcd;
}
}
}
int main(){
//ios::sync_with_stdio(false);
init();
cin >> t;
for(int i = 1; i <= t; i ++){
cin >> a >> b >> year;
if(judge(year))day[2] = 29;
else day[2] = 28;
printf("Case #%d: ",i);
int x, y;
int flag = 0;
for(int i = 1; i <= 12; i ++){
for(int j = 1; j <= day[i]; j ++){
if(arr[i][j].gcd==a && arr[i][j].lcm==b){
flag ++;
x = i, y = j;
}
}
}
if(flag==0)printf("-1\n");
else if(flag==1) printf("%d/%02d/%02d\n",year,x,y);
else printf("1\n");
}
return 0;
}