题目
题解
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void gao(ll pa,ll pb,ll qa,ll qb,ll &x,ll &y){
ll z=(pa+pb-1)/pb;
if(z<=qa/qb){
x=z; y=1; return;
}
pa-=(z-1)*pb; qa-=(z-1)*qb;
gao(qb,qa,pb,pa,y,x);
x+=(z-1)*y;
}
ll a,p,x,y;
int main(){
int T; cin>>T;
while(T--){
scanf("%lld%lld",&p,&a);
gao(p,a,p,a-1,x,y);
ll z=x*a-p*y;
printf("%lld/%lld\n",z,x);
}
return 0;
}
来源:https://blog.csdn.net/BX2359575459/article/details/99318879