题目链接
//hdoj 4551 //2013-05-26-20.52 #include <stdio.h> int day[2][13] = {{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}}; int judge(int y) { if (y%4 == 0 && y % 100 != 0 || y % 400 == 0) return 1; else return 0; } int gcd(int x, int y) { if (x%y == 0) return y; else return gcd(y, x%y); } int main() { int x, y, z; int t; scanf("%d" ,&t); for (int k = 1; k <= t; k++) { scanf("%d %d %d", &x, &y, &z); int year = judge(z); int a, b; int cnt = 0; for (int i = 1; i <= 12; i++) { for (int j = 1; j <= day[year][i]; j++) { if (gcd(i, j) == x && i*j/gcd(i, j) == y) { a = i, b = j; cnt++; } } } if (cnt == 0) printf("Case #%d: -1\n", k); else if (cnt > 1) printf("Case #%d: 1\n", k); else printf("Case #%d: %04d/%02d/%02d\n", k, z, a, b); } return 0; }