思路:类欧几里得
代码:
#pragma GCC optimize(2)#pragma GCC optimize(3)#pragma GCC optimize(4)#include using namespace std;#define y1 y11#define fi first#define se second#define pi acos(-1.0)#define LL long long//#define mp make_pair#define pb push_back#define ls rt<<1, l, m#define rs rt<<1|1, m+1, r#define ULL unsigned LL#define pll pair #define pli pair #define pii pair #define piii pair #define pdd pair #define mem(a, b) memset(a, b, sizeof(a))#define debug(x) cerr << #x << " = " << x << "\n";#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);//headint T;LL a, b, c, d, p, q;//a/b < p/q < c/dvoid solve(LL a, LL b, LL c, LL d) { if(a == 0) { p = 1; q = d/c+1; return ; } if(a >= b) { solve(a%b, b, c-(a/b)*d, d); p += (a/b)*q; return ; } if(c > d) { p = q = 1; return ; } solve(d, c, b, a); swap(p, q);}int main() { scanf("%d", &T); while(T--) { scanf("%lld %lld %lld %lld", &a, &b, &c, &d); solve(a, b, c, d); printf("%lld/%lld\n", p, q); } return 0;}