fork download
  1.  
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7. int a,b,c,d;
  8. cin>>a>>b>>c>>d;
  9.  
  10. int len = 10010;
  11. int arr[len]= {false};
  12.  
  13. for (int i=b;i<len;i+=a){
  14. arr[i] = 1;
  15. }
  16.  
  17. for(int i=d;i<len;i+=c){
  18. if(arr[i]){
  19. cout<<i;
  20. exit(0);
  21. }
  22. }
  23. cout<<-1;
  24.  
  25. return 0;
  26. }
  27.  
  28.  
Success #stdin #stdout 0s 16064KB
stdin
99 100
100 1
stdout
9901