#include #include #include typedef long long int int64; #define MAX(a,b) ((a)>(b)?(a):(b)) #define MIN(a,b) ((a)<(b)?(a):(b)) #define ABS(a) ((a)>(0)?(a):-(a)) typedef struct fraction{ int64 nu; int64 de; } frac; int64 gcd(int64 a,int64 b){ int64 r=a%b; while(r>0){ a=b;b=r;r=a%b; } return b; } void add(frac *c,frac *a,frac *b){ int64 x=a->nu*b->de+a->de*b->nu; if(x==0){ c->nu=0; c->de=1; return; } int64 y=a->de*b->de; c->nu=x; c->de=y; return; } void sub(frac *c,frac *a,frac *b){ int64 x=a->nu*b->de-a->de*b->nu; if(x==0){ c->nu=0; c->de=1; return; } int64 y=a->de*b->de; c->nu=x; c->de=y; return; } void mul(frac *c,frac *a,frac *b){ int64 x=a->nu*b->nu; if(x==0){ c->nu=0; c->de=1; return; } int64 y=a->de*b->de; c->nu=x; c->de=y; return; } void division(frac *c,frac *a,frac *b){ int64 x=a->nu*b->de; if(x==0){ c->nu=0; c->de=1; return; } int64 y=a->de*b->nu; if(y<0){ y=-y; x=-x; } c->nu=x; c->de=y; return; } frac stack[7]; int test; int b[6]; int num; int calc(int top){ if(top==1 && stack[0].nu%stack[0].de==0 && stack[0].nu/stack[0].de==test) return 1; //operator if(top>=2){ frac a=stack[top-2]; frac b=stack[top-1]; add(stack+top-2,&a,&b);if(calc(top-1)) return 1; sub(stack+top-2,&a,&b);if(stack[top-2].nu>0 && calc(top-1)) return 1; mul(stack+top-2,&a,&b);if(calc(top-1)) return 1; if(b.nu!=0) division(stack+top-2,&a,&b);if(calc(top-1)) return 1; stack[top-2]=a; stack[top-1]=b; } //push int i; for(i=0;i