比赛 |
2025.9.13 |
评测结果 |
AAAAAAAAAAAA |
题目名称 |
Transforming Pairs |
最终得分 |
100 |
用户昵称 |
汐汐很希希 |
运行时间 |
0.180 s |
代码语言 |
C++ |
内存使用 |
3.68 MiB |
提交时间 |
2025-09-13 08:47:11 |
显示代码纯文本
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=110;
const int M=2010;
const int MOD=998244353;
int T;
int main()
{
freopen("Transforming.in","r",stdin);
freopen("Transforming.out","w",stdout);
cin>>T;
while(T)
{
T--;
ll a,b,c,d;
cin>>a>>b>>c>>d;
ll ans=0;
if(c<a||d<b){
cout<<-1<<endl;
continue;
}else if(c==a&&d==b){
cout<<0<<endl;
continue;
}
bool flag=true;
while(c!=a||d!=b){
if(c<a||d<b){
cout<<-1<<endl;
flag=false;
break;
}
if(c>=d){
ll t=(c-a)/d;
ans+=max(t,1ll);
c-=max(t,1ll)*d;
}else if(c<d){
ll t=(d-b)/c;
ans+=max(t,1ll);
d-=max(t,1ll)*c;
}
}
if(flag) cout<<ans<<endl;
}
return 0;
}