import java.util.*;
import java.io.*;

public class elevator_gk {
    private final static long INF = 1000000000000000000L;
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        long h = scanner.nextLong();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();

        long[] q = new long[c];
        long[] v = new long[c];
        Arrays.fill(q, INF);
        Arrays.fill(v, INF);

        for (long z = 0; z < c; z++) {
            long f = a * z;
            int yc = (int) (f % c);
            for (long y = f; v[yc] == INF; y += b) {
                int xc = (int) (y % c);
                for (long x = y; q[xc] == INF; x += a) {
                    q[xc] = x;
                    xc = (xc + a) % c; 
                }

                f = Math.min(f, q[yc]);
                v[yc] = f;
                f += b;
                yc = (yc + b) % c;
            }
        }

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

        PrintWriter w = new PrintWriter(System.out);
        w.println(ok);
        w.close();
    }
}
