using System;
namespace untc
{
class Fraction
{
private long numerator;
private ushort denumerator;
public long Numerator { get => numerator; }
public ushort Denumerator { get => denumerator; }
public override string ToString()
{
return String.Format("{0}/{1}", this.numerator, this.denumerator);
}
private void optimise()
{
long n = this.numerator;
long d = this.denumerator;
long remainder;
while (d != 0)
{
remainder = n % d;
n = d;
d = remainder;
}
this.numerator /= n;
this.denumerator /= (ushort)n;
}
public static Fraction operator +(Fraction a, Fraction b)
{
return new Fraction(a.Numerator * b.Denumerator + b.Numerator * a.Denumerator, a.Denumerator * b.Denumerator);
}
public static Fraction operator -(Fraction a, Fraction b)
{
return new Fraction(a.Numerator * b.Denumerator - b.Numerator * a.Denumerator, a.Denumerator * b.Denumerator);
}
public static Fraction operator *(Fraction a, Fraction b)
{
return new Fraction(a.Numerator * b.Numerator, a.Denumerator * b.Denumerator);
}
public static Fraction operator /(Fraction a, Fraction b)
{
return new Fraction(a.Numerator * b.Denumerator, a.Denumerator * b.Numerator);
}
public static bool operator ==(Fraction a, Fraction b)
{
return a.Numerator == b.Numerator && a.Denumerator == b.Denumerator;
}
public static bool operator !=(Fraction a, Fraction b)
{
return a.Numerator != b.Numerator || a.Denumerator != b.Denumerator;
}
public Fraction(long numerator, long denumerator)
{
if (denumerator == 0)
{
throw new System.ArgumentException();
}
if (numerator < 0 && denumerator < 0)
{
numerator = Math.Abs(numerator);
denumerator = Math.Abs(denumerator);
}
if (denumerator < 0 && denumerator > 0 || denumerator > 0 && numerator < 0)
{
numerator = -Math.Abs(numerator);
denumerator = Math.Abs(denumerator);
}
optimise();
}
}
}
return String.Format("{0}/{1}", this.numerator, this.denumerator);
if (numerator < 0 && denumerator < 0)
{
numerator = Math.Abs(numerator);
denumerator = Math.Abs(denumerator);
}
if (denumerator < 0 && denumerator > 0 || denumerator > 0 && numerator < 0)
{
numerator = -Math.Abs(numerator);
denumerator = Math.Abs(denumerator);
}
if (numerator < 0 && denumerator < 0)
{
this.numerator = Math.Abs(numerator);
this.denumerator = Math.Abs(denumerator);
}
if (denumerator < 0 && denumerator > 0 || denumerator > 0 && numerator < 0)
{
this.numerator = -Math.Abs(numerator);
this.denumerator = Math.Abs(denumerator);
}