import math
a, b, x, y = map(int, input().split()) # a, b - max width, max height , x, y - width, height
g = math.gcd(x,y)

x //= g
y //= g

print(min(a//x, b//y))

line = list(map(int, input().split()))
a = line[0]
b = line[1]
x = line[2]
y = line[3]

def gcd(a,b):
    while a != 0 and b != 0:
        if a > b:
            a %= b
        else:
            b %= a
    return a + b

j = gcd(x, y)
x //= j
y //= j

n = 0
k1 = a // x
k2 = b // y
n = min(k1, k2)
print(n)

import math
a,b,x,y=map(int,input().split())
z=math.gcd(x,y)
x//=z
y//=z
print(min(a//x,b//y))

def gcd(a,b):
    if a==0:
        return b
    return gcd(b%a,a)

a,b,x,y=map(int,str(input()).strip().split())
while(gcd(x,y)!=1):
    t=gcd(x,y)
    x//=t
    y//=t
r=a//x
p=b//y
print(min(r,p))

a = input()
b = []
for i in range(len(a)):
    if a[i] == " " :
        c = i
        b.append(c)

d =[a[:int(b[0])]]
for j in range(len(b)-1) :
    e = a[int(b[j])+1:int(b[j+1])]
    d.append(e)
f = a[int(b[len(b)-1]):]
d.append(f)
m = int(d[0])
n = int(d[1])
x = int(d[2])
y = int(d[3])

def hcfnaive(a,b):
    if(b==0):
        return a
    else:
        return hcfnaive(b,a%b)

h = hcfnaive(x,y)#=2
t = x/h#=1
u = y/h#=2
v = n//u#=1
w = m//t#=3
if v*t/u <= m and w*u/t <= n:
    first = int(v)#=1
    second = int(w)
    print(min(first,second))
elif v*t/u > m and w*u/t <= n:
    first = 0
    second = int(w)
    print(second)
elif v*t/u <= m and w*u/t > n:
    first = int(v)
    second = 0
    print(first)
else :
    first = second = 0
    print(first)

import math
a,b,x,y=map(int,input().split())
g=math.gcd(x,y)
x//=g;y//=g
print(min(a//x,b//y))

def getMin(a,b):
    if (a == b) :
        return int(b)
    if (a < b):
        return int(a)
    else:
        return int(b)

def getGCD(a,b):
    while a != 0 and b != 0:
        if a > b:
            a %= b
        else:
            b %= a
    gcd = a + b
    return gcd

nums = [int(x) for x in input().split()]
a = nums[0]
b = nums[1]

x = nums[2]
y = nums[3]

gcd = getGCD(x,y)

a_x = a // ( x / gcd )
b_y = b // ( y / gcd )

print(getMin(a_x, b_y))

import sys

array = input().split(" ")
a,b,x,y = int(array[0]) , int(array[1]), int(array[2]), int(array[3])

def pgcd(a,b):
    """pgcd(a,b): calcul du 'Plus Grand Commun Diviseur' entre les 2 nombres entiers a et b"""
    while b != 0:
        r=a%b
        a,b=b,r
    return a

# p = PGCD_x_y(x,y)
p = pgcd(x,y)
# print(a,b,x,y)
# print(p)
k1 = a//(x/p)
k2 = b//(y/p)

if k1 < k2 :
    print(int(k1))
else :
    print(int(k2))

import math
a,b,x,y = map(int,input().split(" "))

gc = math.gcd(x,y)

x = int(x/gc)
y = int(y/gc)

count = 0
t = min(a//x,b//y)

print(t)

gcd = lambda a, b: gcd(b, a % b) if b else a

a, b, x, y = map(int, input().split())
g = gcd(x, y)
print(min(a // (x // g), b // (y // g)))

from math import gcd

a, b, x, y = map(int, input().split())
m = gcd(x, y)
print(min(a * m // x, b * m // y))

import math
a,b,x,y=map(int,input().split())
d=math.gcd(x,y)
print(min(a*d//x,b*d//y))

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

a, b, x, y = [int(i) for i in input().split()]
L, R = 0, int(1e20)
g = gcd(x, y)
x //= g
y //= g
while R - L > 1:
    M = (L + R) // 2
    w = M * x
    h = M * y
    if w <= a and h <= b:
        L = M
    else:
        R = M
print(L)

def gcd(x, y):
  if y == 0:
    return x
  return gcd(y, x%y)

a, b, x, y = map(int, raw_input().split())
g = gcd(x, y)
x = x / g
y = y / g
c = a / x
d = b / y
ans = 0
if c * y <= b:
    ans = c
if d * x <= a:
    ans = max(ans, d)
print ans

from fractions import gcd
a,b,x,y=map(int,raw_input().split())
s=gcd(x,y)
x=x/s
y=y/s
print min(a/x,b/y)

from fractions import gcd
w, h, x, y = map(int, input().split())
'''
def gcd(a, b):
    if a < b:
        x = a
        a = b
        b = x
    while True:
        mod = a % b

        if mod == 0:
            print(b)
            return b
            break
        a = b
        b = mod
'''

z = gcd(x, y)
x = int(x / z)
y = int(y / z)
widths = int(w/x)
heights = int(h/y)
if widths > heights:
    print(heights)
else:
    print(widths)

maxw,maxh,w,h = map(int,raw_input().split(" "))

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a % b)

temp = gcd(w,h)
n = maxw/(w/temp)
m = maxh/(h/temp)
if(n>m):
    print m
else:
    print n

import sys

# m > n
def gcd(m, n):
    while True:
        if n == 1 or m % n == 0:
            break
        (m, n) = (n, m % n)
    return n

def main():
    data = sys.stdin.readline().split(' ')

    a = int(data[0])
    b = int(data[1])
    x = int(data[2])
    y = int(data[3])
    k = 1
    if x > y:
        k = gcd(x, y)
    else:
        k = gcd(y, x)
    x /= k
    y /= k
    print min(a / x, b / y)

if __name__ == "__main__":
    main()

#!/usr/bin/env python

from sys import stdin, stderr

def gcd(a, b):
   if b == 0:
      return a
   else:
      return gcd(b, a % b)

def main():
   a, b, x, y = map(int, stdin.readline().split())
   d = gcd(x, y)
   x /= d
   y /= d
   res = min(a/x, b/y)
   print(res)
   return 0

if __name__ == '__main__': main()

a,b,x,y = map(int, raw_input().split())
def gcd(a,b):
    while b:
        a, b = b, a%b
    return a

g = gcd(x,y)
x/=g
y/=g

mn = min(a/x, b/y)
print mn

from fractions import gcd
a, b, x, y = map(int, raw_input().split())
g = gcd(x, y)
x /= g
y /= g
print min(a / x, b / y)

def gcd(a, b):
    x = max(a, b)
    y = min(a, b)
    while x != 0 and y != 0:
        x = x % y
        if x == 0: break
        y = y % x
    return max(x, y)

a, b, x, y = map(int, input().split())
h = gcd(x, y)
def gcd(a, b):
    x = max(a, b)
    y = min(a, b)
    while x != 0 and y != 0:
        x = x % y
        if x == 0: break
        y = y % x
    return max(x, y)
x //= h
y //= h
if a/x < b/y: print(a // x)
else: print(b // y)

import heapq as hq
import math

a, b, x, y = [int(i) for i in input().split(" ")]
g = math.gcd(x, y)
x /= g
y /= g
print(int(min(a // x, b // y)))

def read():
    return list(map(int, input().split()))
a, b, c, d = read()
def gcd(x, y, big = False):
    if not big:
        sum = x + y
        x = max(x, y)
        y = sum - x
    if y == 0:
        return x
    else:
        return gcd(y, x % y, True)
e = gcd(c, d)
c = c // e
d = d // e

print(str(min(a // c, b // d)))

def gcd(a,b):
    while True:
        r=a%b
        if r==0:
            return b
        a=b
        b=r
a,b,x,y=list(map(int,input().split()))
g=gcd(x,y)
x,y=x/g,y/g
print(int(min(a//x,b//y)))

a, b, x, y = map(int, input().split(" "))
def gcd(a, b):
	while(a):
		b = b%a
		a, b = b, a
	return b
kek = gcd(x, y)
x = x/kek
y = y/kek
print(int(min(a/x, b/y)))

a,b,x,y=list(map(int,input().split()))
import math
ab=math.gcd(x,y)
x=x//ab;y=y//ab
print(min(a//x,b//y))

def nod(a, b):
    if b == 0:
        return a
    else:
        return nod(b, a % b)

a, b, x, y = map(int, input().split())
n = nod(x, y)
x1 = x // n
y1 = y // n
print(min(a//x1,b//y1))

import math as m
a,b,c,d = map(int,input().split())
z = m.gcd(c,d)
c,d = c//z,d//z
print(min(a//c,b//d))

from fractions import gcd
a,b,x,y=map(int,raw_input().split())
u=gcd(x,y)
x,y=x/u,y/u
print min(a/x,b/y)

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

a,b,x,y=map(int, input().split())

k = gcd(x,y)
x //= k
y //= k

print(min(a//x, b//y))

def gcd(a,b):
	if b==0:
		return a
	return gcd(b,a%b)
a,b,x,y=map(int,raw_input().split())
g=gcd(x,y)
x/=g
y/=g
print min(a/x,b/y)

def nod(a, b):
    if b == 0:
        return a
    return nod(b, a % b)

[a, b, x, y] = [int(i) for i in input().split()]
n = nod(x, y)
x /= n
y /= n
print(int(min(a // x, b // y)))

a,b,x,y = map(int, raw_input().split())

def gcd(x,y):
    if x<y:
        x,y=y,x
    while y:
        x,y=y,x%y
    return x

k=gcd(x,y)
x,y=x/k,y/k

k1=a/x
k2=b/y

print min(k1,k2)
exit()

def hcf(a,b):
    if b==0:
        return a
    return hcf(b,a%b)
a,b,x,y = list(map(int,input().split()))
k = hcf(x,y)
x,y = x//k,y//k
print(min(a//x,b//y))

a, b, x, y = map(int, input().split())

def gcd(x, y):
	while x!=0 and y!=0:
		if x >= y:
			x = x%y
		elif y > x:
			y = y%x
	return x+y

f = gcd(x,y)
x /= f
y /= f

ans = int(min(a//x, b//y))
print(ans)

from fractions import Fraction as F
import math
import sys

fi = sys.stdin
fo = sys.stdout
fe = sys.stderr
exit = sys.exit

readline = raw_input

def readargs(tp=None):
	if tp is not None:
		return map(tp, readline().split())
	return readline().split()

def yesno(flag, yes='', no=''):
	if flag:
		print yes if yes else 'YES'
	else:
		print no if no else 'NO'

truefalse = lambda flag : yesno(flag, yes='TRUE', no='FALSE')

a, b, x, y = map(int, readline().split())

def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)

g = gcd(x, y)
x /= g
y /= g

print min([a / x, b / y])

def gcd(a, b):
    if a == 0:
        return b
    return gcd(b % a, a)

if __name__ == "__main__":
    a, b, x, y = tuple(map(int, input().split()))
    if x / y > a / b:  # wiidth is limiting
        print(a//(x//gcd(x,y)))
    else:  # height is limiting

        print(b//(y//gcd(x,y)))

from fractions import gcd;

a,b,x,y = map(int, raw_input().split())

lc = gcd(x,y); ans = 0

lcx = x / lc; lcy = y / lc

gx = a - x; gy = b - y;

#print lcx, lcy, gx, gy

g1 = 0; g2 = 0

if lc == 1 and (x > a or y > b):

	print 0

else:

	print min(a/lcx, b/lcy)

#print g1, g2, gx, lcx, gy, lcy

w,h,x,y = map(int,raw_input().split())

w2=(x*h)/y

def gcd(x,y):
	if(y==0):
		return x

	return gcd(y,x%y)

gc=gcd(x,y)
x/=gc
y/=gc

lef=0
rig=h/y
ans=0
# print(gc,rig)
while(lef<=rig):
	mid=(lef+rig)/2
	temp=(x*mid)
	if(temp<=w):
		ans=mid
		lef=mid+1
	else:
		rig=mid-1

print(ans)

from fractions import Fraction
a,b,x,y = map(int, input().split())
sx = Fraction(x, y).numerator
sy = Fraction(x, y).denominator
print(int(min(a//sx, b//sy)))

from fractions import gcd;
a, b, x, y = map(int, input().split())
g = gcd(x, y)
x //= g
y //= g
print(min(a // x, b // y))

from math import *;a,b,c,d=map(int,input().split());e=gcd(c,d);c//=e;d//=e;print(min(a//c,b//d))

from fractions import Fraction
import math as maths

#a/b == x/y
params = input()
a, b, x, y=int(params.split(" ")[0]),int(params.split(" ")[1]),int(params.split(" ")[2]),int(params.split(" ")[3])

if not (x%y) == 0:
	xMin, yMin = int(str(Fraction(x,y)).split("/")[0]),int(str(Fraction(x,y)).split("/")[1])
else:
	xMin, yMin = x/y, 1

options=[]
options.append(a//xMin)
options.append(b//yMin)

print(int(min(options)))

import math
s = input().split()
a = int(s[0])
b = int(s[1])
x = int(s[2])
y = int(s[3])
g = math.gcd(x, y)
x //= g
y //= g
print(min(a//x, b//y))

a,b,x,y=map(int,input().split())
def hcfnaive(a,b):
    if(b==0):
        return a
    else:
        return hcfnaive(b,a%b)

s= hcfnaive(x,y)
h=x//s
c=y//s
k=a//h
z=b//c
if(k!=0 and z!=0):
    print(min(k,z))
else:
    print(0)

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

a, b, x, y = map(int, input().split())

num = x // gcd(x, y)
den = y // gcd(x, y)

ans = min(a // num, b // den)

print(ans)

a,b,xx,yy=map(int,input().split())
x=xx
y=yy
while (x!=0) and (y!=0):
    if x>y:
        x=x%y
    else:
        y=y%x
print(min(a//(xx//(x+y)),b//(yy//(x+y))))

import math

def gcd(a,b):
    return gcd(b,a % b) if b else a

while True:
    try:
        a,b,x,y = map(int,input().strip().split())

        tp = gcd(x,y)
        x = x // tp
        y = y // tp

        print(min(a // x,b // y))
    except:
        break

s=input()
lis=s.split(" ")
def hcf(a,b):
    if(a%b==0):
        return b
    else:
        return hcf(b,a%b)
k=hcf(int(lis[2]),int(lis[3]))
a=int(int(lis[0])//(int(lis[2])/k))
b=int(int(lis[1])//(int(lis[3])/k))
print(min(a,b))

import math
a,b,c,d=map(int,input().split())
divisor=math.gcd(c,d)
c//=divisor
d//=divisor
print(min(a//c,b//d))

import math
a,b,x,y=list(map(int,input().split()))
g=math.gcd(x,y)
x=x//g
y=y//g
print(min(a//x,b//y))

def GCD(a, b):
	while (a != 0 and b != 0):
		a, b = b % a, a
	return max(a, b)
a, b, x, y = map(int, input().split())
f = GCD(x, y)
x //= f
y //= f
n = min(a, b * x // y)
print(n // x)

from fractions import gcd

a, b, x, y = map(int, raw_input().split())
g = gcd(x, y)
x /= g
y /= g
print min(a / x, b / y)

from fractions import gcd
ch = input().split(' ')

ls = []

for i in ch:
    ls.append(i)

a,b = float(ls[0]), float(ls[1])
x,y = int(ls[2]), int(ls[3])

uc = gcd(x,y)

x = int(x/uc)
y = int(y/uc)
#print(x,y)
tu = a/x
mau = b/y
#print(tu,mau)
if tu >= mau:
    print(int(mau))
elif tu < mau:
    print(int(tu))
else:
    print(0)

a, b, x, y = map(int, raw_input().split())

def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)

g = gcd(x, y)
x /= g
y /= g

num_width = a / x
num_height = b / y

print min(num_width, num_height)

from __future__ import division, print_function

from fractions import Fraction
from sys import __stdout__, setrecursionlimit, stdin, stdout

input = lambda: stdin.readline().rstrip()
print = lambda *args: stdout.write(' '.join(str(x) for x in args) + '\n')

def main():
    a, b, x, y = map(int, input().split())
    ratio = Fraction(x, y)
    print(min(a // ratio.numerator, b // ratio.denominator))

if __name__ == '__main__':
    main()

from fractions import gcd
a,b,x,y=map(int,raw_input().split())
z=gcd(x,y)
x/=z
y/=z
print min(a//x,b//y)

#import resource
#import sys
#resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
#import threading
#threading.stack_size(2**26)
#sys.setrecursionlimit(0x1000000)
from sys import stdin, stdout
mod=(10**9)+7
mod1=mod-1
def modinv(n,p):
    return pow(n,p-2,p)
def ncr(n,r,p):
    t=((fact[n])*(modinv(fact[r],p)%p)*(modinv(fact[n-r],p)%p))%p
    return t
def GCD(x, y):
   while(y):
       x, y = y, x % y
   return x
def BS(arr, l, r, x):
    if r >= l:
        mid = l + (r - l)/2
        if arr[mid] == x:
            return mid
        elif arr[mid] > x:
            return BS(arr, l, mid-1, x)
        else:
            return BS(arr, mid+1, r, x)
    else:n -1
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
import math
import heapq
from random import randint as rn
from Queue import Queue as Q
def comp(x,y):
    if(x[0]<y[0]):
        return -1
    elif(x[0]==y[0]):
        if(x[1]<y[1]):
            return -1
        else:
            return 1
    else:
        return 1
def rec(x,n,y):
    if(n==y):
        x=tuple(x)
        if(d.has_key(x)):
            d[x]+=1
        else:
            d[x]=1
        return
    for i in range(y):
        t=x[:]
        t[n],t[i]=t[i],t[n]
        rec(t,n+1,y)
#credits:TDS115/yolaaa kyonki plagarism me pakda gaya randi
"""*********************************************************************************"""
a,b,x,y=map(int,raw_input().split())
r=GCD(x,y)
x/=r
y/=r
q=a/x
r=b/y
print min(q,r)

def gcd(a, b):
    if a == 0:
        return b
    else:
        return gcd(b % a, a)

max_w, max_h, w, h = map(int, input().split())
g = gcd(w, h)
w /= g
h /= g

ans = min(max_w // w, max_h // h)

print(int(ans))

a, b, x, y = [int(i) for i in input().split(' ')]

def nod(a,b):
    while a!=0 and b!=0:
        if a > b:
            a = a % b
        else:
            b = b % a

    return a + b

c = nod(x,y)
x = x / c
y = y / c

print(min(int(a / x), int(b / y)))

import math as m
a, b, x, y = [int(x) for x in input().split()]
k = m.gcd(x,y)
xn = x//k
yn = y//k
print(min(a//xn, b//yn))

from math import gcd

a,b,x,y = map(int,input().split())
z = gcd(x,y)
z1,z2 = x//z,y//z
print(min(a//z1,b//z2))

from math import gcd
a, b, x, y = map(int, input().split())

div = gcd(x, y)
x //= div
y //= div

print(min(a // x , b // y))

import math
a,b,x,y=map(int,input().split())
sum=0
o=math.gcd(x,y)
x=x/o
y=y/o
print(int(min(a//x,b//y)))

#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
#from bisect import bisect_left as bl                #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br               #c++ upperbound br(array,element)

import math
def main():
    a,b,x,y=map(int,input().split(" "))
    '''w<=a
    h<=b
    and w/h==x/y
    y*w=x*h
    lcm(x,y) ka multiple
    such that la
    '''
    temp=math.gcd(x,y)
    x=x//temp
    y=y//temp
    print(min(a//x,b//y))

#-----------------------------BOSS-------------------------------------!
# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

a,b,x,y=[int(x) for x in input().split()]

def gcd(u,v):
	if v==0:
		return u
	else:
		return gcd(v,u%v)
g=gcd(x,y)
x=x//g
y=y//g
print(min(a//x,b//y))

import sys
input = sys.stdin.readline
from collections import *

def gcd(x, y):
    while y:
        x, y = y, x%y
    return x

a, b, x, y = map(int, input().split())
G = gcd(x, y)
x //= G
y //= G
print(min(a//x, b//y))

import math

a,b,x,y = map(int,input().split())

d = math.gcd(x,y)

x /= d
y /= d

print(int(min(a//x,b//y)))

def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)

def main():
    a, b, x, y = map(int, input().split(' '))
    maxw = None
    maxh = None

    g = gcd(x, y)
    x //= g
    y //= g

    maxw = a - a % x
    maxh = b - b % y

    if maxw * y <= maxh * x:
        maxh = maxw * y // x
    else:
        maxw = maxh * x // y

    if maxw < x or maxh < y:
        print(0)
    else:
        print(int(min((maxw - x) // x + 1, (maxh - y) // y + 1)))

if __name__ == '__main__':
    main()

def gcd(a, b):
    while b > 0:
        temp = a % b
        a = b
        b = temp
    return a
a,b,x,y = map(int,input().split())
gc = gcd(x,y)
x2 = x // gc
y2 = y // gc
x4 = a // x2
y4 = b // y2

if x4 * y2 <= b:
    print(x4)
elif y4 * x2 <= a:
    print(y4)
else:
    print(0)

"""https://codeforces.com/contest/1041/problem/B"""
a,b,x,y = tuple(map(int, input().split()))

if x<y: a,b,x,y = b,a,y,x

def GCD(a,b):
    if b==0: return a
    else: return GCD( b, a%b )

gcd = GCD(x,y)
x = x//gcd
y = y//gcd

print( min( a//x, b//y ) )

from math import gcd
a,b,x,y=map(int,input().split())
g = gcd(x,y)
x/=g
y/=g
print(int(min(a//x, b//y)))

from math import gcd

a,b,x,y=map(int,input().split())

d=gcd(x,y)
x=x//d
y=y//d

print(min(a//x,b//y))

'''def gcd(a,b):
    while a != b:
        if a > b:
            a = a - b
        else:
            b = b - a
    return a'''

def gcd (a, b):
    while b:
        a, b = b, a % b
    return abs(a)

a, b, x, y = (int(x) for x in input().split())
x1 = x
y1 = y
i = gcd(x,y)
x //= i
y //= i
print(min(a//x,b//y))

def gcd(a,b):
    while b > 0:
        a, b = b, a % b
    return a

a, b, x, y = map(int, input().split())
x, y = x // gcd(x, y), y // gcd(x, y)
print(min(a // x, b // y))

#https://codeforces.com/problemset/problem/1041/B
def gcd(a,b):
	if a%b==0:
		return b
	return gcd(b,a%b)
from math import log2
a,b,x,y=map(int,input().split())
k=gcd(x,y)
x=x//k
y=y//k
print(min(a//x,b//y))

__author__ = 'Esfandiar'
import sys
from math import gcd
input=sys.stdin.readline
a,b,x,y = map(int,input().split())
while True:
    t = gcd(x,y)
    if t == 1:break
    x//=t
    y//=t
print(min(a//x,b//y))

import math
a,b,x,y=map(int,input().split())
k=math.gcd(x,y)
x=x//k
y=y//k
print(min((a//x),(b//y)))

def gcd(a,b):
    if a<b:
        a,b=b,a
    if b==0:
        return a
    return gcd(b,a%b)

def f(ll):
    a,b,x,y = ll    #3e5
    g = gcd(x,y)
    x = x // g
    y = y // g
    return min(a//x,b//y)

l = list(map(int,input().split()))
print(f(l))

#author : SanskarxRawat
import math
a,b,x,y=map(int,input().strip().split())
g=math.gcd(x,y)
print(min(a*g//x,b*g//y))

import math
a,b,x,y=map(int,input().split())
sum=0
o=math.gcd(x,y)
x=x/o
y=y/o
print(min(a//x,b//y))

def gcd(a, b):
    while b > 0:
        temp = a % b
        a = b
        b = temp
    return a
a,b,x,y = map(int,input().split())
gc = gcd(x,y)
x2 = x // gc
y2 = y // gc
x4 = a // x2
y4 = a // y2
if x4 * y2 <= b:
    print(x4)
elif y4 * x2 <= a:
    print(y4)
else:
    print(0)

a,b,x,y=[int(el) for el in input().split()]

xx=x
yy=y
while xx%yy!=0 and yy%xx!=0:
    if xx>yy:
        xx=xx-yy*int(xx/yy)
    else:
        yy=yy-xx*int(yy/xx)

x=x/yy
y=y/yy

if a<x or b<y:
    print ('0')
    raise SystemExit()

out=min(a/x, b/y)
print (int(out))

a,b,x,y=[int(el) for el in input().split()]

while x>y:
    x=x-y
while y>x:
    y=y-x

if a<x or b<y:
    print ('0')
    raise SystemExit()

out=min(a/x, b/y)
print (int(out))

a,b,x,y=[int(el) for el in input().split()]

xx=x
yy=y
while xx>yy:
    xx=xx-yy
while yy>xx:
    yy=yy-xx

x=int(x/yy)
y=int(y/yy)

if a<x or b<y:
    print ('0')
    raise SystemExit()

out=min(a/x, b/y)
print (int(out))

a,b,c,d=map(int,input().split())
a=a//c
b=b//d
print(min(a,b))

a, b, x, y = map(int, input().split())
print(min(a // x, b // y))

import math

a,b,x,y = list(map(int,input().strip().split()))
ans = 0

g = math.gcd(x,y)

x = x/g
y = y/g

ans = min(math.floor(a/x),math.floor(a/y))

# for w in range(1,a+1):
#     for h in range(1,b+1):
#         if (w/h) == (x/y):
#             ans += 1

print(ans)

def HCF(a,b):
	if(b==0):
		return a
	return HCF(b , a % b)

a,b,x,y = map(int , input().split())
hcf = HCF(x,y)
x = x//hcf
y = y//hcf
if(x>y):
	ans = (a//x)
	print(ans)
else:
	ans = (b//y);
	print(ans)

a,b,x,y = input().split()
a=int(a)
b=int(b)
x=int(x)
y=int(y)
c=1
s=0
f=[]
for d in range (1,10**9):
	if (((x%d)==0) and (y%d==0)):
		f.append(d)
	if ((d>x) or (d>y)):
		break
print (f)
x = (x/f[-1])
y = (y/f[-1])
print (x)
print (y)
while ((a>=(x*c)) and (b>=(y*c))):
	c+=1
	s+=1
print (s)

s = input().split()
a = int(s[0])
b = int(s[1])
x = int(s[2])
y = int(s[3])
a1 = max(a, b)
b1 = min(a, b)
x1 = max(x, y)
y1 = min(x, y)
a1 -= a1 % x1
b1 -= b1 % y1
print(int(min(a1/x1, b1/y1)))

import math
s = input().split()
a = int(s[0])
b = int(s[1])
x = int(s[2])
y = int(s[3])
a1 = max(a, b)
b1 = min(a, b)
x1 = max(x, y) // math.gcd(x, y)
y1 = min(x, y) // math.gcd(x, y)
a1 -= a1 % x1
b1 -= b1 % y1
print(int(min(a1/x1, b1/y1)))

a,b,x,y=map(int,input().split())
def hcfnaive(a,b):
    if(b==0):
        return a
    else:
        return hcfnaive(b,a%b)

s= hcfnaive(x,y)
h=x//s
c=y//s
k=a//h
z=b//c
print(k)

a,b,x,y=map(int,input().split())
def hcfnaive(a,b):
    if(b==0):
        return a
    else:
        return hcfnaive(b,a%b)

s= hcfnaive(x,y)
h=x//s
c=y//s
k=a//h
z=b//c
if(k!=0 and z!=0):
    print(k)
else:
    print(0)

import math

a,b,x,y = map(int,input().split())

x//=math.gcd(x,y)
y//=math.gcd(x,y)

r1 = a//x
r2 = b//y

if r1 < r2:print(r1)
else: print(r2)

import math

a,b,x,y = map(int,input().split())

x//=math.gcd(x,y)
y//=math.gcd(x,y)

r1 = a/x
r2 = b/y

if r1 < r2:print(r1)
else: print(r2)

import math
a,b,x,y=map(int,input().split())
z=math.gcd(x,y)
x=x//z
y=y//z
if(x>a or y>b):
	print(0)
else:
	print(max(a,b)//max(x,y))

import math
a,b,x,y=map(int,input().split())
z=math.gcd(x,y)
flag=0
if(z>1):
	while 1:
		if(x%z!=0 or y%z!=0):
			break
		else:
			x=x//z
			y=y//z
if(x>a or y>b):
	print(0)
	flag=1
if(flag==0):
	print(max(a,b)//max(x,y))

import math
a,b,x,y=map(int,input().split())
z=math.gcd(x,y)
# print(z)
flag=0
if(z>1):
	while 1:
		if(x%z!=0 or y%z!=0):
			break
		else:
			x=x//z
			y=y//z
	# print(x,y)
if(x>a or y>b):
	print(0)
	flag=1
if(flag==0):
	if(min(a,b)>max(x,y)):
		print(min(a,b)//max(x,y))
	else:
		print(max(a,b)//max(x,y))

def findNOD(a, b):
    while(a!=0 and b!=0):
        if(a>b):
            a = a%b
        else:
            b = b%a
    return (a+b)

inp = input().split()
a = int(inp[0])
b = int(inp[1])
x = int(inp[2])
y = int(inp[3])

nodOfXY = findNOD(x, y)
x = x//nodOfXY
y = y//nodOfXY

print(min((max(a,b)//max(x,y)), min(a,b)//min(x,y)))

def findNOD(a, b):
    while(a!=0 and b!=0):
        if(a>b):
            a = a%b
        else:
            b = b%a
    return (a+b)

inp = input().split()
a = int(inp[0])
b = int(inp[1])
x = int(inp[2])
y = int(inp[3])

nodOfXY = findNOD(x, y)
x = x//nodOfXY
y = y//nodOfXY

print(max(a,b)//max(x,y))

a,b,x,y = map(int,input().split())
print(min(a//x,b//y))

while True:
    try:
      n = eval(input().strip())

      a = list(map(int,input().strip().split()))

      a = sorted(a)

      res = 0
      for i in range(1,n):
          res += a[i] - a[i - 1] - 1

      print(res)
    except:
        break

def gcd(a, b):
    x = min(a, b)
    y = max(a, b)

    while x > 0:
        t = y
        y = x
        x = t % y

    return y

a, b, x, y = map(int, input().split())
k = gcd(x, y)
while(k > 1):
    x //= k
    y //= k
    k = gcd(x, y)
print(k, x, y)

print(min(a//x, b//y))

s=input()
lis=s.split(" ")
a=int(lis[0])//int(lis[2])
b=int(lis[1])//int(lis[3])
print(min(a,b))

a,b,c,d=map(int,input().split())
if d>c:
    c,d=d,c
c1,d1=c,d
e=d
while e!=0:
    c,e,d=e,c%d,c
c1=c1//c
d1=d1//c
print(max(a,b)//c1)

import math
a,b,x,y=list(map(int,input().split()))
g=math.gcd(x,y)
print(min(a//x,b//y))

def gcd(a, b):
    while b > 0:
        c = a
        a = b
        b = c % b
    return a

nums = list(map(int, input().split()))
a = nums[0]
b = nums[1]
x = nums[2]
y = nums[3]
h = min(b, (a * y) // x)
w = min(a, (b * x) // y)
d = gcd(x, y)
ans = min(w // x, h // y)
print(ans)

def gcd(a, b):
    while b > 0:
        c = a
        a = b
        b = c % b
    return a

nums = list(map(int, input().split()))
a = nums[0]
b = nums[1]
x = nums[2]
y = nums[3]
h = min(b, (a * y) // x)
w = min(a, (b * x) // y)
d = gcd(x, y)
ans = min(w / x, h / y)
print(ans)

from math import gcd
from functools import reduce
h, w, x, y = map(int, input().split())
a = str(x) + ':' + str(y)
def solve(ratio):
    numbers = [int(i) for i in ratio.split(':')]
    denominater = reduce(gcd, numbers)
    solved = [i / denominater for i in numbers]
    return ':'.join(str(int(i)) for i in solved)
a = solve(a)
x, y = map(int, a.split(':'))
print(min(w // x, h // y))

def GCD(a, b):
	while (a != 0 and b != 0):
		a, b = b % a, a
	return max(a, b)
a, b, x, y = map(int, input().split())
f = GCD(x, y)
x //= f
n = min(a, b * x // y)
print(n // x)

a,b,x,y = map(int,input().split())
if y > x:
    tmp = y
    y = x
    x = tmp
masx = x
masy = y
while x % y:
    x, y = y, x % y
x, y = masx//y, masy//y
if a/x >= b/y:
    print(b//y)
else :
    print(a//x)

a,b,x,y = map(int,input().split())
if y > x:
    tmp = y
    y = x
    x = tmp
masx = x
masy = y
while x % y:
    x, y = y, x % y
x, y = masx//y, masy//y
if a//x > b//y:
    print(b//y)
else :
    print(a//x)

import math

arr = [int(s) for s in input().split()]
a = arr[0]
b = arr[1]
x = arr[2]
y = arr[3]

g = math.gcd(x, y)

x /= g
y /= g

w = a//x
h = b//y

if w > h :
    print(h)
else:
    print(w)

def gcd(a, b):
    if a == 0:
        return b
    else:
        return gcd(b % a, a)

max_w, max_h, w, h = map(int, input().split())
g = gcd(w, h)
w /= g
h /= g

ans = min(max_w // w, max_h // h)

print(ans)

a,b,x,y=[int(x) for x in input().split()]
h=0
w=0
k=0
while h<=a and w<=b :
	h+=x
	w+=y
	k+=1
print(k-1)

a,b,x,y=[int(x) for x in input().split()]
h=0
w=0
k=0
while h<a and w<b :
	h+=y
	w+=x
	k+=1
print(k)

a,b,x,y=[int(x) for x in input().split()]
h=0
w=0
k=0
while h<a and w<b :
	h+=y
	w+=x
	k+=1
if h==a or w==b:
	print(k)
else:
	print(k-1)

def getMin(a,b):
    if (a == b) :
        return b
    if (a < b):
        return a
    else:
        return b

def getGCD(a,b):
    while a != 0 and b != 0:
        if a > b:
            a %= b
        else:
            b %= a
    gcd = a + b
    return gcd

nums = [int(x) for x in input().split()]
a = nums[0]
b = nums[1]

x = nums[2]
y = nums[3]

gcd = getGCD(x,y)

a_x = a // ( x / gcd )
b_y = b // ( y / gcd )

print(getMin(a_x, b_y))

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

a, b, x, y = [int(i) for i in input().split()]
L, R = 0, int(1e18)
g = gcd(x, y)
x //= g
y //= g
while R - L > 1:
    M = (L + R) // 2
    w = M * x
    h = M * y
    if w <= a and h <= b:
        L = M
    else:
        R = M
print(L)

w, h, x, y = map(int, input().split())
widths = int(w/x)
heights = int(h/y)
if widths > heights:
    print(heights)
else:
    print(widths)

import fractions
string =raw_input()
A = string.split()
a=int(A[0])
b=int(A[1])
x=int(A[2])
y=int(A[3])
m= max(x,y)
cnt=0
# def hcfnaive(a,b):
#     if(b==0):
#         return a
#     else:
#         return hcfnaive(b,a%b)
# if (x%hcfnaive(x,y) ==0 ) and (y%hcfnaive(x,y) ==0):
#     ucln = hcfnaive(x,y)
#     x = x/ucln
#     y = y/ucln
for i in range (1, m):
    if x*i<= a:
        if y*i<=b:
            cnt = cnt+1
print cnt

import fractions
string =raw_input()
A = string.split()
a=int(A[0])
b=int(A[1])
x=int(A[2])
y=int(A[3])
m= max(x,y)
cnt=0
# if fractions.gcd(x,y)%x ==0 AND fractions.gcd(x,y)%y ==0:
#     x = fractions.gcd(x,y)/x
#     y = fractions.gcd(x,y)/y
for i in range (1, m):
    if x*i<= a:
        if y*i<=b:
            cnt = cnt+1
print cnt
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

a,b,x,y=map(int,raw_input().split(" "))

def gcc_(a,b):
	if b==0 :
		return a
	else:
		return gcc_(b,a%b)
div = gcc_(x,y)

print min(a/x/div,b/y/div)

#import sys; sys.stdin = open('input.txt')

def cin(obj=list, type=int, sep=' '):
    return obj(map(type, input().split(sep)))

a, b, x, y = cin()

print(min(a // x, b // y))

def nod(a, b):
	a = int(a)
	b = int(b)
	if(a > b):
		a, b = b, a
	if(b % a == 0):
		return a
	else:
		while(b != 0):
			if(a > b):
				a, b = b, a
			x = b // a
			b -= x * a
		return a

s = input()
s = s.split()

a = int(s[0])
b = int(s[1])
x = int(s[2])
y = int(s[3])

q = nod(x, y)
x = x // q
y = y //q

if(a > b):
	a, b = b, a
	x, y = y, x

i = a

while i * y // x > b:
	i -= x

print(i // x)

arr = list(input().split(' '))
a, b, x, y = int(arr[0]), int(arr[1]), int(arr[2]), int(arr[3])
res = 0
cur_x, cur_y = x, y
res = min(a//x, b//y)
print(res)
##print(a, b, x, y)
##print(x/y)

a, b, x, y = map(int, input().split())
print(min (a // x, b // y))

def gcd(a, b):
    while (b != 0):
        a, b = b, a % b
    return a
a, b, x, y = map(int, input().split())
t = gcd(x, y)
print(min (a // t, b // t))

def check(A,B,X,Y,mid):
    if(X*mid <= A and Y*mid <= B) :
        return True
    return False
def gcd(a,b) :

    if(a==0) :
        return b;

    return gcd(b%a,a);

a=list(map(int,input().strip().split(' ')))
A,B,X,Y= a[0],a[1],a[2],a[3]
lw = 1
hg = 10**20
g=gcd(X,Y)
X=X//g
Y=Y//g
while lw <=hg :

     mid = (lw+hg)//2
     flag = check(A,B,X,Y,mid)
     #print(mid,flag)
     if(flag==True) :
         if(mid==0):
             print("0")
             break ;
         if(check(A,B,X,Y,mid+1)==False):
            print(mid)
            break ;
     if(flag==True) :
        lw=mid+1
     else :
        hg=mid-1

a = input()
b = []
for i in range(len(a)):
    if a[i] == " " :
        c = i
        b.append(c)

d =[a[:int(b[0])]]
for j in range(len(b)-1) :
    e = a[int(b[j])+1:int(b[j+1])]
    d.append(e)
f = a[int(b[len(b)-1]):]
d.append(f)
m = int(d[0])
n = int(d[1])
x = int(d[2])
y = int(d[3])

def hcfnaive(a,b):
    if(b==0):
        return a
    else:
        return hcfnaive(b,a%b)

h = hcfnaive(x,y)#=2
t = x/h#=1
u = y/h#=2
v = n//u#=1
w = m//t#=3
if v*t/u <= m :
    first = int(v)#=1
else:
    first = 0
if w*u/t <= n:
    second = int(w)
else:
    second = 0
if first != 0 and second != 0:
    print(min(first,second))
elif first != 0 and second == 0:
    print(first)
elif second != 0 and first == 0:
    print(second)

array = input().split(" ")
a,b,x,y = int(array[0]) , int(array[1]), int(array[2]), int(array[3])

def pgcd(a,b):
    """pgcd(a,b): calcul du 'Plus Grand Commun Diviseur' entre les 2 nombres entiers a et b"""
    while b != 0:
        r=a%b
        a,b=b,r
    return a

# p = PGCD_x_y(x,y)
p = pgcd(x,y)
# print(a,b,x,y)
# print(p)
k1 = a//(x/p)
k2 = b//(y/p)

if k1 < k2 :
    print(k1)
else :
    print(k2)

import math

a,b,x,y=map(int,input().split())

x=x//math.gcd(x,y)

y=y//math.gcd(x,y)

print(min(a//x,b//y))

from fractions import Fraction
a, b, x, y = list(map(int, input().split()))

pocz = 1
kon = 1e18+5
srd = 0
f = Fraction(x, y)
k = -1

while kon - pocz > 1:
    srd = (kon + pocz) // 2

    if f.numerator * srd <= a and f.denominator * srd <= b:
        if pocz == srd:
            print(int(pocz))
            exit()
        pocz = srd
    else:
        kon = srd

if srd == 2:
    if f.numerator * 2 <= a and f.denominator * 2 <= b:
        pass
    elif f.numerator <= a and f.denominator <= b:
        srd = 1
    else:
        srd = 0

print(int(srd))

from fractions import Fraction
a, b, x, y = list(map(int, input().split()))

pocz = 1
kon = 1e18+5
srd = 0
f = Fraction(x, y)

while kon - pocz > 1:
    srd = (kon + pocz) // 2

    if f.numerator * srd <= a and f.denominator * srd <= a:
        pocz = srd
    else:
        kon = srd

if srd == 2:
    if f.numerator * 2 <= a and f.denominator * 2 <= a:
        pass
    elif f.numerator <= a and f.denominator <= a:
        srd = 1
    else:
        srd = 0

print(int(srd))

from fractions import Fraction
a, b, x, y = list(map(int, input().split()))

pocz = 1
kon = 1e18+5
srd = 0
f = Fraction(x, y)

while kon - pocz > 1:
    srd = (kon + pocz) // 2

    if f.numerator * srd <= a and f.denominator * srd <= a:
        pocz = srd
    else:
        kon = srd

if srd == 2:
    if f.numerator * 2 <= a and f.denominator * 2 <= a:
        pass
    elif f.numerator * 2 <= a and f.denominator * 2 <= a:
        srd = 1
    else:
        srd = 0

print(int(srd))

a,b,x,y = map(int,input().split())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def simplify_fraction(numer, denom):
    common_divisor = gcd(numer, denom)
    (reduced_num, reduced_den) = (numer / common_divisor, denom / common_divisor)

    if reduced_den == 1:
        return [1,1]
    elif common_divisor == 1:
        return [numer, denom]
    else:
        return [reduced_num, reduced_den]

simplified = simplify_fraction(x,y)
print(int(min(a//simplified[0],b//simplified[1])))

import heapq as hq
import math

a, b, x, y = [int(i) for i in input().split(" ")]
g = math.gcd(x, y)
x /= g
y /= g
print(min(a // x, b // y))

def read():
    return list(map(int, input().split()))
a, b, c, d = read()
def hcf(x, y):
    b = max(x, y)
    s = min(x, y)
    yu_mul = 1
    while (True):
        yu = b % s
        if yu == 0: return yu_mul * s
        if yu == 1: break
        if (b % yu == 0) and (s % yu == 0):
            b = b // yu
            s = s // yu
            yu_mul *= yu
            continue
        break
    return yu_mul
e = hcf(c, d)
c = c // e
d = d // e

print(str(min(a // c, b // d)))

# -*- coding: utf-8 -*-
"""
Created on Sun Dec 23 14:56:55 2018

@author: QuocBinh
"""
import math

a,b,x,y=map(int,input().split())
t=math.gcd(x,y)
x=x//t
y=y//t
print(min(x,y))

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

a,b,x,y=map(int, input().split())

k = gcd(x,y)
x /= k
y /= k

print(min(a//x, b//y))

def nod(a, b):
    if b == 0:
        return a
    return nod(b, a % b)

[a, b, x, y] = [int(i) for i in input().split()]
n = nod(x, y)
x /= n
y /= n
print(max(a // x, b // y))

def nod(a, b):
    if b == 0:
        return a
    return nod(b, a % b)

[a, b, x, y] = [int(i) for i in input().split()]
n = nod(x, y)
x /= n
y /= n
print(int(max(a // x, b // y)))

def nod(a, b):
    if b == 0:
        return a
    return nod(b, a % b)

[a, b, x, y] = [int(i) for i in input().split()]
n = nod(x, y)
x /= n
y /= n
print(min(a // x, b // y))

import sys

line1 = sys.stdin.readline().strip().split()
arr = []
for i in line1:
   arr.append(int(i))
#print(arr)
a = arr[0]
b = arr[1]
x = arr[2]
y = arr[3]
#count = 0
#for w in range(1,a+1):
#   for h in range(1,b+1):
#      if y*w == x*h:
#         #print(w, h)
#         count += 1
#print(count)
flag = 1
w = 0
ww = 0
hh = 0
while flag == 1 and w <= a:
   w+=1
   ww = w
   for h in range(1,b+1):
      hh = h
      if y*w == x*h:
         flag = 0
#print(w, h)
print(a/w)

import sys

line1 = sys.stdin.readline().strip().split()
arr = []
for i in line1:
   arr.append(int(i))
#print(arr)
a = arr[0]
b = arr[1]
x = arr[2]
y = arr[3]
#count = 0
#for w in range(1,a+1):
#   for h in range(1,b+1):
#      if y*w == x*h:
#         #print(w, h)
#         count += 1
#print(count)
flag = 1
w = 0
ww = 0
hh = 0
while flag == 1 and w <= a:
   w+=1
   ww = w
   for h in range(1,b+1):
      hh = h
      if y*w == x*h:
         flag = 0
#print(w, h)
print(int(round(a/w, 0)))

import sys

line1 = sys.stdin.readline().strip().split()
arr = []
for i in line1:
   arr.append(int(i))
#print(arr)
a = arr[0]
b = arr[1]
x = arr[2]
y = arr[3]
#count = 0
#for w in range(1,a+1):
#   for h in range(1,b+1):
#      if y*w == x*h:
#         #print(w, h)
#         count += 1
#print(count)
flag = 1
w = 0
ww = 0
hh = 0
while flag == 1:
   w+=1
   ww = w
   for h in range(1,b+1):
      hh = h
      if y*w == x*h:
         flag = 0
#print(w, h)
print(a/w)

import sys
from fractions import gcd

line1 = sys.stdin.readline().strip().split()
arr = []
for i in line1:
   arr.append(int(i))
a = arr[0]
b = arr[1]
x = arr[2]
y = arr[3]
g = gcd(x,y)
print(g)
x /= g;
y /= g;
print(x, y)
print(min(int(a/x), int(b/y)))

import math
G = math.gcd
F = math.floor
import decimal
D = decimal.Decimal
l1 = [int(x) for x in input().split()]
a,b,x1,y1  = l1[0],l1[1],l1[2],l1[3]
x = D(min(x1,y1)/G(x1,y1))
y = D(max(x1,y1)/G(x1,y1))
width = min(a,b)
length = max(a,b)
#print(width,length)
if length<y or width<x:
    print(0)
else:
    print(min(F(D(length/y)),F(D(int(width/x)))))

import math
G = math.gcd
F = math.floor
import decimal
D = decimal.Decimal
l1 = [int(x) for x in input().split()]
a,b,x1,y1  = l1[0],l1[1],l1[2],l1[3]
x = min(x1,y1)
y = max(x1,y1)
width = min(a,b)*G(x,y)
length = max(a,b)*G(x,y)
#print(width,length)
if length<y or width<x:
    print(0)
else:
    print(min(F(D(length/y)),F(D(int(width/x)))))

import math
G = math.gcd
F = math.floor
import decimal
D = decimal.Decimal
l1 = [int(x) for x in input().split()]
a,b,x1,y1  = l1[0],l1[1],l1[2],l1[3]
x = D(min(x1,y1)/G(x1,y1))
y = D(max(x1,y1)/G(x1,y1))
width = min(a,b)
length = max(a,b)
#print(width,length)
if length<y or width<x:
    print(0)
else:
    first = str((D(length/y)))
    if "." in first:
        first = "".join(list(first)[:first.index(".")])
    second = str(D(int(width/x)))
    if "." in second:
        second = "".join(list(second)[:second.index(".")])

    first1 = first.rjust(10**5,"0")
    second1 = second.rjust(10**5,"0")
    if first1>second1:
        print(second)
    else:
        print(first)

import math
G = math.gcd
l1 = [int(x) for x in input().split()]
a,b,x1,y1  = l1[0],l1[1],l1[2],l1[3]
x = min(x1,y1)
y = max(x1,y1)
width = min(a,b)*G(x,y)
length = max(a,b)*G(x,y)
#print(width,length)
if length<y or width<x:
    print(0)
else:
    print(min(int(length/y),int(width/x)))

def hcf(a,b):
    if b==0:
        return a
    return hcf(b,a%b)
a,b,x,y = list(map(int,input().split()))
print(x,y)
k = hcf(x,y)
x,y = x//k,y//k
print(min(a//x,b//y))

a, b, x, y = map(int, input().split())
print(min(a // x, b // y))

a,b,x,y = (map(int,input().split()))
count=0
res=0
for i in range(a):
    if i%x==0:
        count+=1
for i in range(b):
    if i%y==0:
        res+=1
print(min(count-1,res-1))

def gcd(a,b):
    if a==0:
        return b
    return gcd(b%a,a)

a,b,x,y=map(int,str(input()).strip().split())
while(gcd(x,y)!=1):
    t=gcd(x,y)
    x//=t
    y//=t
r=a//x
p=b//y
print(min(r,b))

def compute_gcd(x,y):
    #print(x,y)
    if y==0:
        return x
    else:
        return compute_gcd(y,x%y)

a, b, x, y = map(int, input().split())

gcd = compute_gcd(x,y)
#print(gcd)
num_x, num_y = x/gcd, y/gcd
count = 0
while num_x<=a and num_y<=b:
    count += 1
    num_x += x
    num_y += y

print(count)