标签:
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int m,n; 6 void build(int x,int y,int t1,int t2,int &ans1,int &ans2) 7 { 8 int a,b; 9 if (t2==m) {ans1=1;ans2=1;return ;} 10 if (t1==n) 11 { 12 if (x==0) ans2=1; 13 else ans2=0; 14 ans1=1; 15 return ; 16 } 17 build(y,0,t1,t2+1,ans1,ans2); 18 a=ans1; 19 b=ans2; 20 build(y,1,t1+1,t2,ans1,ans2); 21 a+=ans1; 22 b+=ans2; 23 if (x==0&&y==1) b+=a; 24 ans1=a; 25 ans2=b; 26 } 27 int main() 28 { 29 int a,b,c,ans1,ans2; 30 while (~scanf("%d%d",&n,&m)) 31 { 32 build(-1,0,0,1,ans1,ans2); 33 a=ans1;b=ans2; 34 build(-1,1,1,0,ans1,ans2); 35 a+=ans1;b+=ans2; 36 n=b; 37 m=a; 38 a=max(n,m); 39 b=min(n,m); 40 c=1; 41 while (c) 42 { 43 c=a%b; 44 a=b; 45 b=c; 46 } 47 printf("%d/%d\n",n/a,m/a); 48 } 49 return 0; 50 }
标签:
原文地址:http://www.cnblogs.com/pblr/p/4728291.html