Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- long long int nod(long long int a,long long int b) {
- if (b < a) {
- int r = b;
- b = a;
- a = r;
- }
- while (a > 0) {
- b -= a;
- if (b < a) {
- int r = b;
- b = a;
- a = r;
- }
- }
- return b;
- }
- long long int nok(long long int a, long long int b) {
- if (a > 1e9 || b > 1e9) return 1000000001;
- else
- return a * b / nod(a, b);
- }
- int main() {
- long long int k, l, m, n, i = 1, p = 0;
- cin >> k >> l >> m >> n;
- 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);
- cout << p;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement