import java.math.BigInteger;

public class BigFraction {
	BigInteger n;
	BigInteger d;

	public BigFraction(BigInteger n, BigInteger d) {
		this.n = n;
		this.d = d;
	}

	public BigFraction add(BigFraction a) {
		return new BigFraction(this.d.multiply(a.n).add(a.d.multiply(this.n)), this.d.multiply(a.d));
	}

	public BigFraction subtract(BigFraction a) {
		return new BigFraction(a.d.multiply(this.n).subtract(this.d.multiply(a.n)), this.d.multiply(a.d));
	}

	public BigFraction multiply(BigFraction a) {
		return new BigFraction(this.n.multiply(a.n), this.d.multiply(a.d));
	}

	public BigFraction divide(BigFraction a) {
		return new BigFraction(this.n.multiply(a.d), a.n.multiply(this.d));
	}

	public BigFraction reduce() {
		BigInteger gcd = this.n.gcd(this.d);
		if (gcd.compareTo(BigInteger.ZERO) != 0) {
			this.n = this.n.divide(gcd); // BLANK_6
			this.d = this.d.divide(gcd); // BLANK_7
		}
		return this;
	}
	
	public boolean equals(BigFraction a) {
		BigFraction ra = new BigFraction(a.n, a.d);
		BigFraction rt = new BigFraction (this.n, this.d);
		
		ra = ra.reduce();
		rt = rt.reduce();
		
		return (ra.n.equals(rt.n) && ra.d.equals(rt.d));
	}

	public String toString() {
		if (this.d.compareTo(BigInteger.ZERO) < 0)
			return this.n.multiply(new BigInteger("-1")) + "/" + this.d.multiply(new BigInteger("-1"));
		else
			return this.n + "/" + this.d;
	}
}