Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
- template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
- #define forn(i, n) for (int i = 0; i < (int)(n); i++)
- #define forab(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
- long long a, b, c, d;
- bool ok(long long p1, long long q1, long long p2, long long q2) {
- return p1 * q2 < p2 * q1;
- }
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cin >> a >> b >> c >> d;
- long long ans = 0;
- while (ok(a, b, c, d)) {
- a++;
- b++;
- long long f = __gcd(a, b);
- a /= f;
- b /= f;
- ans++;
- if (a == c && b == d) {
- cout << ans;
- return 0;
- }
- }
- cout << 0;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement