CF1720A Burenka Plays with Fractions 题解
题目的目标是让两个分数满足以下条件:
把上面的式子变形一下,得:
所以,如果开始时给定的
那如果不满足呢?
为方便处理,不妨设
放代码:
#include<bits/stdc++.h>
#define int long long // 记得开 long long,不然你会连样例都过不去
using namespace std;
main(){
ios::sync_with_stdio(false);
int t; cin>>t;
while(t--){
int a,b,c,d; cin>>a>>b>>c>>d,a*=d,b*=c;
if(a==b)cout<<"0\n";
else if(b&&a%b==0||a&&b%a==0)cout<<"1\n"; // 如果一个是另一个的倍数
// 注意,要特判除数是 0!!!
else cout<<"2\n";
}
return 0;
}