Advertisement
Josif_tepe

Untitled

Apr 7th, 2025
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5.  
  6. ll dist(ll x, ll y, ll x2, ll y2) {
  7.     return llabs(x - x2) + llabs(y - y2);
  8. }
  9. int main() {
  10.     ll W, H, C, R;
  11.     cin >> W >> H >> C >> R;
  12.    
  13.     ll x = W / C;
  14.     ll res1 = dist(x * C, x * R, W, H);
  15.    
  16.     x++;
  17.     ll res2 = dist(x * C, x * R, W, H);
  18.    
  19.     x = H / R;
  20.     ll res3 = dist(x * C, x * R, W, H);
  21.    
  22.     x++;
  23.     ll res4 = dist(x * C, x * R, W, H);
  24.    
  25.     cout << min(min(res1, res2), min(res3, res4)) << endl;
  26.    
  27.    
  28.    
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement