Saleh127

e-olym 43

Sep 10th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. ll k,n,m,d,ans,c,i,j;
  11. cin>>k>>n>>m>>d;
  12. c=(k*n)/__gcd(k,n);
  13. c=(c*m)/__gcd(m,c);
  14. for(i=1; ;i++)
  15. {
  16. ans=c*i;
  17. if(ans/k+ans/n+ans/m==ans-d)
  18. {
  19. cout<<ans<<endl;
  20. return 0;
  21. }
  22. else if(ans/k+ans/n+ans/m<ans-d)
  23. {
  24. cout<<-1<<endl;
  25. return 0;
  26. }
  27. }
  28.  
  29.  
  30. return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment