mfgnik

Untitled

Apr 16th, 2020
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. std::pair<int, int> NormalizePair(int first, int second) {
  2.     if (first == 0) {
  3.         if (second > 0) {
  4.             return {0, second};
  5.         }
  6.         return {0, -second};
  7.     }
  8.     auto divisor = std::gcd(first, second);
  9.     if (first < 0) {
  10.         divisor *= -1;
  11.     }
  12.     return {first / divisor, second / divisor};
  13. }
Advertisement
Add Comment
Please, Sign In to add comment