Bobo has two fractions xaxa and ybyb. He wants to compare them. Find the result.
输入描述:
The input consists of several test cases and is terminated by end-of-file. Each test case contains four integers x, a, y, b. * 0≤x,y≤1018 * 1≤a,b≤109 * There are at most 105 test cases.
输出描述:
For each test case, print `=` if x/a=y/b. Print `<` if x/a<y/b. Print `>` otherwise.
这题如果x,y,a,b均为质数,那么使用x*b和y*a来判断超过了long long的位数,如果直接除会造成精度缺失;
所以我们可以考虑把整数部分和小数部分分开求,用a1来代表x/a(整数部分),a2来代表x%a(小数部分),y/b同理;
对于整数部分相同的,我们可以让小数部分进行通分比大小(防止精度损失)
代码如下:
#include<bits/stdc++.h> using namespace std; #define ll long long ll x,y,a,b; int main(){ while(~scanf("%lld%lld%lld%lld",&x,&a,&y,&b)){ ll a1=x/a,b1=y/b; ll a2=x%a*b,b2=y%b*a; if(a1>b1||(a1==b1&&a2>b2)) puts(">"); else if(a1<b1||(a1==b1&&a2<b2)) puts("<"); else puts("="); } }