Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. typedef long long lint;
  9.  
  10. const int N=100*1000;
  11.  
  12. lint n;
  13. lint a, b, c, d;
  14. lint mas[110];
  15. bool r=false;
  16.  
  17. int main() {
  18.     cin>>a>>b>>c>>d;
  19.     if(b<d) {
  20.         swap(a, c);
  21.         swap(b, d);
  22.     }
  23.     for(n=0; n<=max(b, d)+c; n++) {    
  24.         if((b%c+(a%c)*(n%c))%c==d%c ) {
  25.             r=true;
  26.             break;
  27.         }
  28.         //if(mas[n%c]==0) mas[n%c]++;
  29.         //else break;
  30.     }
  31.     if(r) cout<<b+a*n<<endl;
  32.     else cout<<-1<<endl;
  33.    
  34.  
  35.     return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement