#include <cassert>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <stdlib.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
struct frac{
ll up,low;
frac(ll up=0,ll low=1){
if(low<0) up=-up,low=-low;
assert(low);
ll g=gcd(abs(up),low);
this->up=up/g,this->low=low/g;
}
frac operator + (const frac &b) const
{
return frac(up * b.low + low * b.up, low * b.low);
}
frac operator - (const frac &b) const
{
return frac(up * b.low - low * b.up, low * b.low);
}
frac operator * (const frac &b) const
{
return frac(up * b.up, low * b.low);
}
frac operator / (const frac &b) const
{
return frac(up * b.low, low * b.up);
}
bool operator < (const frac &b) const
{
return up * b.low < low * b.up;
}
bool operator == (const frac &b) const
{
return up * b.low == low * b.up;
}
bool operator > (const frac& b) const
{
return b < *this;
}
bool operator <= (const frac& b) const
{
return !(b < *this);
}
bool operator >= (const frac &b) const
{
return !(*this < b);
}
bool operator != (const frac &b) const
{
return up * b.low != low * b.up;
}
frac operator += (const frac &b)
{
return *this = *this + b;
}
frac operator -= (const frac &b)
{
return*this = *this - b;
}
frac operator *= (const frac &b)
{
return *this = *this * b;
}
frac operator /= (const frac &b)
{
return *this = *this / b;
}
};
int main()
{
frac a,b;
a.up=1;
a.low=2;
b.up=1;b.low=3;
frac c=a/b;
printf("%I64d %I64d\n",c.up,c.low);
}
太好啦~~~~