Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <algorithm>
- #include <map>
- using namespace std;
- int main()
- {
- int x, y;
- cin >> x >> y;
- int x1 = min(x, y);
- int y1 = max(x, y);
- cin >> x >> y;
- int x2 = min(x, y);
- int y2 = max(x, y);
- if (x2 > x1 || y2 > y1)
- {
- cout << -1;
- return 0;
- }
- int ans = 0;
- while (x1 != x2)
- {
- if (x1 - x2 > x2)
- {
- x1 = (x1 % 2) + (x1 / 2);
- }
- else
- x1 = x2;
- ans++;
- if (x1 > y1)
- swap(x1, y1);
- }
- while (y1 != y2)
- {
- if (y1 - y2 > y2)
- {
- y1 = (y1 % 2) + (y1 / 2);
- }
- else
- y1 = y2;
- ans++;
- if (x1 > y1)
- swap(x1, y1);
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement