Advertisement
peltorator

Дробь между двумя другими с мин знаменателем

May 19th, 2019
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. rat find_best(rat l, rat r)
  2. {
  3.     if (l.x >= l.y)
  4.     {
  5.         ll d = l.x / l.y;
  6.         rat res = find_best(rat(l.x - d * l.y, l.y), rat(r.x - d * r.y, r.y));
  7.         res.x += res.y * d;
  8.         return res;
  9.     }
  10.     if (r.x > r.y)
  11.         return rat(1);
  12.     rat res = find_best(rat(r.y, r.x), rat(l.y, l.x));
  13.     return rat(res.y, res.x);
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement