比赛 |
2025.9.13 |
评测结果 |
AAAAAAAAAAAA |
题目名称 |
Transforming Pairs |
最终得分 |
100 |
用户昵称 |
Ruyi |
运行时间 |
0.180 s |
代码语言 |
C++ |
内存使用 |
3.68 MiB |
提交时间 |
2025-09-13 09:35:34 |
显示代码纯文本
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll t,a,b,c,d;
ll f(ll a,ll b,ll c,ll d){
ll ans=0;
if(c<a||d<b) return -1;
if(a==c&&b==d) return 0;
while(c>a||d>b){
if(c>d){
if(d==0) return -1;
ll k=(c-a)/d;
if(k==0) return -1;
c-=k*d;
ans+=k;
}else if(d>c){
if(c==0) return -1;
ll k=(d-b)/c;
if(k==0) return -1;
d-=k*c;
ans+=k;
}else return -1;
}
if(a==c&&b==d) return ans;
return -1;
}
int main(){
freopen("Transforming.in","r",stdin);
freopen("Transforming.out","w",stdout);
cin>>t;
while(t--){
cin>>a>>b>>c>>d;
cout<<f(a,b,c,d)<<endl;
}
return 0;
}