fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. int a,b,c,d;
  7. cin>>a>>b>>c>>d;
  8. int i=0;
  9. while(true)
  10. {
  11. if( ((b+c*i)/a)-int(((b+c*i)/a))==0)
  12. {
  13. break;
  14. }
  15. else
  16. {
  17. i++;
  18.  
  19. }
  20. }
  21. cout<<(i*c)+d<<endl;
  22. // your code goes here
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 15240KB
stdin
20 2
9 19
stdout
19