#include <stdlib.h>
#include <stdio.h>

#define long long long

const long inf = 1000000000000000000LL;

const int n = 1000000;
int c;

long key[n + 1];
bool u[n + 1];

int size;

int extractMin() {
    long min = inf;
    int mini = 0;
    for (int i = 0; i < c; i++) {
        if (!u[i]) {
            if (min > key[i]) {
                min = key[i];
                mini = i;
            }
        }
    }
    u[mini] = true;
    size--;
    return mini;
}

int main() {

    long h;
    int a, b;
    scanf("%I64i%i%i%i", &h, &a, &b, &c);

    for (int i = 0; i < c; i++) {
        key[i] = inf;
        u[i] = false;
    }
    size = c;

    key[0] = 0;
    while (size != 0) {
        int i = extractMin();
        if (key[i] == inf) break;
        if (key[(i + a) % c] > key[i] + a) {
            key[(i + a) % c] = key[i] + a;
        }
        if (key[(i + b) % c] > key[i] + b) {
            key[(i + b) % c] = key[i] + b;
        }
    }

    long ok = 0;
    for (int i = 0; i < c; i++) {
        if (key[i] < h) {
            ok += ((h - 1) - key[i]) / c + 1;
        }
    }

    printf("%lld\n", ok);
}
