E题:氢氟玩桌游题解
我们发现,答案就是将 加
后,把
和
进行约分,如果约分后
(分母)是
,那么输出约分后的
,否则输出约分后
和
。
代码实现:
#include<bits/stdc++.h>
using namespace std;
long long gcd(long long a,long long b){
return a%b==0?b:gcd(b,a%b);
}
int main(){
int t;
scanf("%d",&t);
while(t--){
long long a,b;
scanf("%lld%lld",&a,&b);
b++;
long long t=gcd(a,b);
a/=t;
b/=t;
if(b==1) printf("%lld\n",a);
else{
printf("%lld %lld\n",a,b);
}
}
return 0;
}