#include using namespace std; #define bokusunny ios::sync_with_stdio(false), cin.tie(nullptr); // 有理数クラス // 初期化 O(logN) (NOTE:重い場合、約分の必要がないのであればlogを取れる) // 分母分子が両方とも0でない → マイナスは分子に寄せる&約分 // 分母が0 → 未定義 // 分子が0 → 分母は1で統一 struct Rational { private: long long NUM; // numerator, 分子 long long DENO; // denominator, 分母 void normalize() { if (NUM == 0) { DENO = 1; } else { // ---必要に応じてコメントアウトするとlogが落ちる--- auto g = gcd(NUM, DENO); NUM /= g; DENO /= g; // ------------------------------------------ if (DENO < 0) { NUM *= -1; DENO *= -1; } } } public: Rational(long long num, long long deno) : NUM(num), DENO(deno) { normalize(); // NOTE: num, deno共にintの範囲に収めないと、比較の際にオーバーフローする // llを使いたい && // setやmapを使ってるだけの場合、unorderedに変えると比較演算子を使わないのでオーバーフローしない assert(NUM < INT_MAX); assert(DENO < INT_MAX); } Rational(long long n) : NUM(n), DENO(1){}; long long num() const { return NUM; } long long deno() const { return DENO; } double to_d() { return (double)NUM / DENO; } bool operator<(const Rational &b) const { return NUM * b.DENO < b.NUM * DENO; } bool operator>(const Rational &b) const { return NUM * b.DENO > b.NUM * DENO; } bool operator<=(const Rational &b) const { return NUM * b.DENO <= b.NUM * DENO; } bool operator>=(const Rational &b) const { return NUM * b.DENO >= b.NUM * DENO; } bool operator==(const Rational &b) const { return NUM == b.NUM && DENO == b.DENO; } bool operator!=(const Rational &b) const { return !(*this == b); } Rational operator+=(const Rational &x); Rational operator+=(long long x); Rational operator-=(const Rational &x); Rational operator-=(long long x); Rational operator*=(const Rational &x); Rational operator*=(long long x); Rational operator/=(const Rational &x); Rational operator/=(long long x); }; inline Rational operator+(const Rational &a, const Rational &b) { long long num = a.num() * b.deno() + a.deno() * b.num(); long long deno = a.deno() * b.deno(); return Rational(num, deno); } inline Rational operator-(const Rational &a, const Rational &b) { long long num = a.num() * b.deno() - a.deno() * b.num(); long long deno = a.deno() * b.deno(); return Rational(num, deno); } inline Rational operator*(const Rational &a, const Rational &b) { long long num = a.num() * b.num(); long long deno = a.deno() * b.deno(); return Rational(num, deno); } inline Rational operator/(const Rational &a, const Rational &b) { long long num = a.num() * b.deno(); long long deno = a.deno() * b.num(); return Rational(num, deno); } inline Rational Rational::operator+=(const Rational &x) { *this = *this + x; return *this; } inline Rational Rational::operator+=(long long x) { *this = *this + Rational(x); return *this; } inline Rational Rational::operator-=(const Rational &x) { *this = *this - x; return *this; } inline Rational Rational::operator-=(long long x) { *this = *this - Rational(x); return *this; } inline Rational Rational::operator*=(const Rational &x) { *this = *this * x; return *this; } inline Rational Rational::operator*=(long long x) { *this = *this * Rational(x); return *this; } inline Rational Rational::operator/=(const Rational &x) { *this = *this / x; return *this; } inline Rational Rational::operator/=(long long x) { *this = *this / Rational(x); return *this; } inline ostream &operator<<(ostream &os, const Rational &f) { os << f.num(); if (f.deno() != 1) os << "/" << f.deno(); return os; } namespace std { template <> struct hash { size_t operator()(const Rational &f) const { size_t seed = 0; // メンバ変数の数だけ行う auto num_hash = hash()(f.num()); seed ^= num_hash + 0x9e3779b9 + (seed << 6) + (seed >> 2); auto deno_hash = hash()(f.deno()); seed ^= deno_hash + 0x9e3779b9 + (seed << 6) + (seed >> 2); return seed; } }; } // namespace std void solve() { int A, B; cin >> A >> B; A %= 12; Rational Long(60 * A + B, 12); Rational Short(B); if (Short > Long) { Long += 60; } auto x = (12 * (Long - Short)) * 60 / 11; cout << x.num() / x.deno() << endl; } int main() { bokusunny; solve(); return 0; }