Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int gcd(int x, int y) {
- x = abs(x);
- y = abs(y);
- while (x != y) {
- if (x > y) {
- x -= y;
- }
- else {
- y -= x;
- }
- }
- return x;
- }
- pair<int, int> relax(pair<int, int> a) {
- int g = gcd(a.first, a.second);
- a.first /= g;
- a.second /= g;
- return a;
- }
- pair<int, int> sum(pair<int, int> a, pair<int, int> b) {
- return relax(make_pair(a.first * b.second + a.second * b.first, a.second * b.second));
- }
- pair<int, int> sub(pair<int, int> a, pair<int, int> b) {
- return relax(make_pair(a.first * b.second - a.second * b.first, a.second * b.second));
- }
- pair<int, int> mul(pair<int, int> a, pair<int, int> b) {
- return relax(make_pair(a.first * b.first, a.second * b.second));
- }
- pair<int, int> div(pair<int, int> a, pair<int, int> b) {
- return relax(make_pair(a.first * b.second, a.second * b.first));
- }
- int main()
- {
- }
Add Comment
Please, Sign In to add comment