Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4. long long int nod(long long int a,long long int b) {
  5. if (b < a) {
  6. int r = b;
  7. b = a;
  8. a = r;
  9. }
  10. while (a > 0) {
  11. b -= a;
  12. if (b < a) {
  13. int r = b;
  14. b = a;
  15. a = r;
  16. }
  17. }
  18. return b;
  19. }
  20.  
  21. long long int nok(long long int a, long long int b) {
  22. if (a > 1e9 || b > 1e9) return 1000000001;
  23. else
  24. return a * b / nod(a, b);
  25.  
  26. }
  27.  
  28. int main() {
  29. long long int k, l, m, n, i = 1, p = 0;
  30. cin >> k >> l >> m >> n;
  31. p = n / k + n / l + n / m - n / nok(k, l) - n / nok(m, l) - n / nok(k, m) + n / nok(nok(m, k), l);
  32. cout << p;
  33.  
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement