fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int happyPeople(int Num1, int Num2, int X, int Y) {
  5. int i = 1;
  6. int countA = 0;
  7. int countB = 0;
  8.  
  9. while (true) {
  10. if (countA < Num1 && i % X != 0) countA++;
  11. if (countB < Num2 && i % Y != 0) countB++;
  12.  
  13. if (countA >= Num1 && countB >= Num2) return i;
  14.  
  15. i++;
  16. }
  17. }
  18.  
  19. int main() {
  20. int Num1, Num2, X, Y;
  21. cin >> Num1 >> Num2 >> X >> Y;
  22. cout << happyPeople(Num1, Num2, X, Y);
  23. return 0;
  24. }
Success #stdin #stdout 0.01s 5304KB
stdin
1 3 2 3
stdout
4