有理数逆元板子
template <int M = 1000000007> struct rational{ ll p, q; rational(ll p = 0, ll q = 1):p(p), q(q){} rational operator + (const rational &rhs) const{ return rational(p * rhs.q + q * rhs.p, q * rhs.q); } rational operator - (const rational &rhs) const{ return rational(p * rhs.q - q * rhs.p, q * rhs.q); } rational operator * (const rational &rhs) const{ return rational(p * rhs.p, q * rhs.q); } rational operator / (const rational &rhs) const{ return rational(p * rhs.q, q * rhs.p); } bool operator < (const rational &rhs) const{ return p * rhs.q < q * rhs.p; } bool operator > (const rational &rhs) const{ return p * rhs.q > q * rhs.p; } bool operator == (const rational &rhs) const{ return p * rhs.q == q * rhs.p; } bool operator != (const rational &rhs) const{ return p * rhs.q != q * rhs.p; } bool operator <= (const rational &rhs) const{ return p * rhs.q <= q * rhs.p; } bool operator >= (const rational &rhs) const{ return p * rhs.q >= q * rhs.p; } void format(){ ll g = __gcd(p, q); p /= g; q /= g; } friend ostream& operator<<(ostream & os, rational rhs) { rhs.format(); os << rhs.p << "/" << rhs.q << endl; } ll inv(){ format(); return (p * quickPow(q, mod - 2)) % mod; } };
天才选手zerol的主页:https://zerol.me/
|
WeepingDemon的个人主页:https://weepingdemon.gitee.io/blog/