Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
  4. template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
  5. #define forn(i, n) for (int i = 0; i < (int)(n); i++)
  6. #define forab(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
  7. long long a, b, c, d;
  8.  
  9. bool ok(long long p1, long long q1, long long p2, long long q2) {
  10. return p1 * q2 < p2 * q1;
  11. }
  12.  
  13. int main() {
  14. ios_base::sync_with_stdio(0);
  15. cin.tie(0);
  16. cin >> a >> b >> c >> d;
  17. long long ans = 0;
  18. while (ok(a, b, c, d)) {
  19. a++;
  20. b++;
  21. long long f = __gcd(a, b);
  22. a /= f;
  23. b /= f;
  24. ans++;
  25. if (a == c && b == d) {
  26. cout << ans;
  27. return 0;
  28. }
  29. }
  30. cout << 0;
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement