fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. int main( ) {
  6. int a,b,c,d;
  7. cin >> a >> b ;
  8. cin >> c >> d;
  9. int gcd = __gcd(a,c);
  10. if( (b-d)% gcd!=0 )
  11. cout << -1;
  12. else
  13. {
  14. while(1)
  15. {
  16. if(b==d)
  17. {cout << b; return 0;}
  18. b += a;
  19. d += c;
  20.  
  21. }
  22.  
  23. }
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0.7s 15240KB
stdin
20 2
9 19
stdout
1171354750