Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::pair<int, int> NormalizePair(int first, int second) {
- if (first == 0) {
- if (second > 0) {
- return {0, second};
- }
- return {0, -second};
- }
- auto divisor = std::gcd(first, second);
- if (first < 0) {
- divisor *= -1;
- }
- return {first / divisor, second / divisor};
- }
Advertisement
Add Comment
Please, Sign In to add comment