kyopro_library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub dyktr06/kyopro_library

:heavy_check_mark: test/yukicoder/yuki_1464.test.cpp

Depends on

Code

#define PROBLEM "https://yukicoder.me/problems/no/1464"
#include <bits/stdc++.h>
using namespace std;

#include "../../lib/math/fraction.hpp"

int main(){
    long double x; cin >> x;
    long long n = x * 100000000 + 0.1;
    fraction<long long> f(n, 100000000);
    cout << f << endl;
}
#line 1 "test/yukicoder/yuki_1464.test.cpp"
#define PROBLEM "https://yukicoder.me/problems/no/1464"
#include <bits/stdc++.h>
using namespace std;

#line 2 "lib/math/fraction.hpp"

/**
 * @brief Fraction
 * @docs docs/math/fraction.md
 */

template <typename T>
struct fraction{
    T p, q; // long long or BigInt
    fraction(T P = 0, T Q = 1) : p(P), q(Q){
        normalize();
    }
    void normalize(){
        T g = __gcd(p, q);
        p /= g, q /= g;
        if(q < 0) p *= -1, q *= -1;
    }
    inline bool operator==(const fraction &other) const {
        return p * other.q == other.p * q;
    }
    inline bool operator!=(const fraction &other) const {
        return p * other.q != other.p * q;
    }
    inline bool operator<(const fraction &other) const {
        return p * other.q < other.p * q;
    }
    inline bool operator<=(const fraction &other) const {
        return p * other.q <= other.p * q;
    }
    inline bool operator>(const fraction &other) const {
        return p * other.q > other.p * q;
    }
    inline bool operator>=(const fraction &other) const {
        return p * other.q >= other.p * q;
    }
    inline fraction operator+(const fraction &other) const { return fraction(p * other.q + q * other.p, q * other.q); }
    inline fraction operator-(const fraction &other) const { return fraction(p * other.q - q * other.p, q * other.q); }
    inline fraction operator*(const fraction &other) const { return fraction(p * other.p, q * other.q); }
    inline fraction operator/(const fraction &other) const { return fraction(p * other.q, q * other.p); }
    inline fraction &operator+=(const fraction &rhs) noexcept {
        *this = *this + rhs;
        return *this;
    }
    inline fraction &operator-=(const fraction &rhs) noexcept {
        *this = *this - rhs;
        return *this;
    }
    inline fraction &operator*=(const fraction &rhs) noexcept {
        *this = *this * rhs;
        return *this;
    }
    inline fraction &operator/=(const fraction &rhs) noexcept {
        *this = *this / rhs;
        return *this;
    }
    friend inline istream &operator>>(istream &is, fraction &x) noexcept {
        is >> x.p;
        x.q = 1;
        return is;
    }
    friend inline ostream &operator<<(ostream &os, const fraction &x) noexcept { return os << x.p << "/" << x.q; }
};
#line 6 "test/yukicoder/yuki_1464.test.cpp"

int main(){
    long double x; cin >> x;
    long long n = x * 100000000 + 0.1;
    fraction<long long> f(n, 100000000);
    cout << f << endl;
}
Back to top page