fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main(){
  6. float k, n, m, d, s;
  7. cin >> k >> n >> m >> d;
  8. s = (d * k * n * m) / (k * n * m - k * m - k * n - m * n);
  9. if((1/k + 1/n + 1/m >= 1) || (floor(s/k) != s/k || floor(s/n) != s/n || floor(s/m) != s/m) || !(floor(s) == s)){
  10. cout << "-1";
  11. }else{
  12. cout << s;
  13. }
  14.  
  15. return 0;
  16. }
Success #stdin #stdout 0s 4384KB
stdin
2 4 7 3
stdout
28