#include <bits/stdc++.h>
int main() {
  int a, b, x, y, m, n;
  m = n = 0;
  scanf("%d%d%d%d", &a, &b, &x, &y);
  for (a; a; a /= x) m = m + a;
  if (m % x == 0) ++m;
  for (b; b; b /= y) n = n + b;
  if (n % y == 0) ++n;
  printf("%d", ((m > n) ? m : n));
  return 0;
}
