#include <cstdio> #include <iostream> #include <cstring> #include <string> #include <fstream> #include <algorithm> #include <ctime> using namespace std; #define MAX(a,b) (a)>(b)?(a):(b) #define INF 0x3f3f3f3f #define MAXN 100010 typedef long long ll; const int mod=1000000009; int gcd(int a,int b) { if(b==0) return a; if(a<b) swap(a,b); return gcd(b,a%b); } int num[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}}; bool check(int year,int m,int d) { int flag=0; if(year%400==0||(year%4==0&&year%100!=0)) flag=1; return d<=num[flag][m]; } int main() { int t; scanf("%d",&t); for(int kase=1;kase<=t;kase++) { int a,b,c; scanf("%d%d%d",&a,&b,&c); printf("Case #%d: ",kase); int ansx,ansy,ansc=0; for(int x=1;x<=12;x++) { if(a*b%x) continue; int y=a*b/x; if(gcd(x,y)==a&&check(c,x,y)) { ansc++; ansx=x; ansy=y; } } if(ansc==0) printf("-1\n"); else if(ansc==1) printf("%d.%02d.%02d\n",c,ansx,ansy); else printf("1\n"); } return 0; } |
Double click to view unformatted code.