Advertisement
999ms

Untitled

Mar 30th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. using ld = long double;
  5.  
  6. ll n,k,a,b;
  7.  
  8. ll get_ans(ll l){
  9.     ll sz = 1LL * n * k;
  10.     ll gcd = __gcd(l, sz);
  11.     sz = sz / gcd;
  12.     return sz;
  13. }
  14.  
  15. int main(){  
  16.     ios_base::sync_with_stdio(false);
  17.     cin.tie(nullptr);
  18.     cin>>n>>k>>a>>b;
  19.     ll x = 2e18;
  20.     ll y = 0;
  21.    
  22.     for(ll l = b - a; l <= 2*n*k; l+=k){
  23.         if(l<=0) continue;
  24.         x = min(x, get_ans(l));
  25.         y = max(y, get_ans(l));
  26.     }
  27.    
  28.     for(ll l = a - b; l <= 2*n*k; l+=k){
  29.         if(l<=0) continue;
  30.         x = min(x, get_ans(l));
  31.         y = max(y, get_ans(l));
  32.     }
  33.    
  34.     for(ll l = a + b - k; l <= 2*n*k; l+=k){
  35.         if(l<=0) continue;
  36.         x = min(x, get_ans(l));
  37.         y = max(y, get_ans(l));
  38.     }
  39.    
  40.     for(ll l = - a - b; l <= 2*n*k; l+=k){
  41.         if(l<=0) continue;
  42.         x = min(x, get_ans(l));
  43.         y = max(y, get_ans(l));
  44.     }
  45.    
  46.    
  47.     cout<<x<<" "<<y<<endl;
  48.     return 0;  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement