// Arup Guha
// 2/11/2017
// Fraction class to be used for Junior Knights Exercise

import java.util.*;

public class fraction {

	private long num;
	private long den;

	// Creates a fraction object from a string that is of the form x/y, where x and y are integers.
	public fraction(String s) {

		// Parse out pieces.
		StringTokenizer tok = new StringTokenizer(s, "/");
		num = Long.parseLong(tok.nextToken());
		den = Long.parseLong(tok.nextToken());

		// Get to lowest terms.
		long div = gcd(Math.abs(num), Math.abs(den));
		num /= div;
		den /= div;

		// Make sure denominator is positive.
		if (den < 0) {
			num = -num;
			den = -den;
		}
	}

	public String toString() {
		return num + "/" + den;
	}

	// Creates a fraction with numerator n, denominator d.
	public fraction(long n, long d) {
		long div = gcd(Math.abs(n), Math.abs(d));
		num = n/div;
		den = d/div;

		// Make sure denominator is positive.
		if (den < 0) {
			num = -num;
			den = -den;
		}
	}

	// Returns this plus other.
	public fraction add(fraction other) {
		long newnum = this.num*other.den + other.num*this.den;
		long newden = this.den*other.den;
		return new fraction(newnum, newden);
	}

	// Returns this minus other.
	public fraction sub(fraction other) {
		long newnum = this.num*other.den - other.num*this.den;
		long newden = this.den*other.den;
		return new fraction(newnum, newden);
	}

	// Returns this times other.
	public fraction mult(fraction other) {
		long newnum = this.num*other.num;
		long newden = this.den*other.den;
		return new fraction(newnum, newden);
	}

	// Returns this divided by other.
	public fraction div(fraction other) {
		long newnum = this.num*other.den;
		long newden = this.den*other.num;
		return new fraction(newnum, newden);
	}

	// Returns this to the power exp.
	public fraction pow(int exp) {
		fraction res = new fraction(1,1);
		for (int i=0; i<exp; i++)
			res = res.mult(this);
		return res;
	}

	// Returns true iff this equals other.
	public boolean equals(fraction other) {
		return this.num*other.den == other.num*this.den;
	}

	// Returns true iff this is greater than other.
	public boolean greaterthan(fraction other) {
		return this.num*other.den > other.num*this.den;
	}

	// Returns true iff this is less than other.
	public boolean lessthan(fraction other) {
		return this.num*other.den < other.num*this.den;
	}

	// Utility, returns the greatest common divisor of a and b.
	private static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a%b);
	}
}