#include <string>
#include <iostream>
#include <sstream>
#include <stdexcept>
int gcd(int a, int b)
{
a = std::abs(a);
b = std::abs(b);
while (a)
{
int temp = a;
a = b % a;
b = temp;
}
return b;
}
struct Rational
{
Rational(std::string);
friend std::ostream& operator<<(std::ostream&, const Rational&);
private:
void reduce();
std::string equation;
int numerator;
int denominator;
};
void Rational::reduce()
{
int divisor = gcd(numerator, denominator);
numerator /= divisor;
denominator /= divisor;
}
Rational::Rational(std::string inputString) : equation(inputString)
{
std::istringstream in(inputString);
char dummy;
if (!(in >> numerator) || !(in >> dummy) || !(in >> denominator))
throw std::invalid_argument("ERROR: Invalid argument - \"" + inputString + '"');
if (denominator == 0)
throw std::domain_error("ERROR: Denominator cannot be 0 - \"" + inputString + '"');
reduce();
}
std::ostream& operator<<(std::ostream& os, const Rational& r)
{
os << r.numerator;
if (r.denominator != 1)
os << " / " << r.denominator;
return os;
}
int main()
{
std::string line;
while (std::getline(std::cin, line) && line.size())
{
try {
std::cout << Rational(line) << '\n';
}
catch (std::exception& ex)
{
std::cout << ex.what() << '\n';
}
std::cout << '\n';
}
}
I2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPHN0ZGV4Y2VwdD4KCmludCBnY2QoaW50IGEsIGludCBiKQp7CiAgICBhID0gc3RkOjphYnMoYSk7CiAgICBiID0gc3RkOjphYnMoYik7CgogICAgd2hpbGUgKGEpCiAgICB7CiAgICAgICAgaW50IHRlbXAgPSBhOwogICAgICAgIGEgPSBiICUgYTsKICAgICAgICBiID0gdGVtcDsKICAgIH0KCiAgICByZXR1cm4gYjsKfQoKc3RydWN0IFJhdGlvbmFsCnsKICAgIFJhdGlvbmFsKHN0ZDo6c3RyaW5nKTsKICAgIGZyaWVuZCBzdGQ6Om9zdHJlYW0mIG9wZXJhdG9yPDwoc3RkOjpvc3RyZWFtJiwgY29uc3QgUmF0aW9uYWwmKTsKCnByaXZ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