1041B. Buying a TV Set

版权声明:大家一起学习,欢迎转载,转载请注明出处。若有问题,欢迎纠正! https://blog.csdn.net/memory_qianxiao/article/details/82730080

B. Buying a TV Set

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than aa and screen height not greater than bb. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is ww, and the height of the screen is hh, then the following condition should be met: wh=xywh=xy.

There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers ww and hh there is a TV set with screen width ww and height hh in the shop.

Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers ww and hh, beforehand, such that (w≤a)(w≤a), (h≤b)(h≤b) and (wh=xy)(wh=xy).

In other words, Monocarp wants to determine the number of TV sets having aspect ratio xyxy, screen width not exceeding aa, and screen height not exceeding bb. Two TV sets are considered different if they have different screen width or different screen height.

Input

The first line contains four integers aa, bb, xx, yy (1≤a,b,x,y≤10181≤a,b,x,y≤1018) — the constraints on the screen width and height, and on the aspect ratio.

Output

Print one integer — the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.

Examples

input

Copy

17 15 5 3

output

Copy

3

input

Copy

14 16 7 22

output

Copy

0

input

Copy

4 2 6 4

output

Copy

1

input

Copy

1000000000000000000 1000000000000000000 999999866000004473 999999822000007597

output

Copy

1000000063

Note

In the first example, there are 33 possible variants: (5,3)(5,3), (10,6)(10,6), (15,9)(15,9).

In the second example, there is no TV set meeting the constraints.

In the third example, there is only one variant: (3,2)(3,2).

题意:在一个长为a,宽为b的墙上挂比例为x/y的的电视,输出能挂多少个(相当于把墙分给为比例为x/y的矩形多少个)。

题解:数论  把x,y最简化,然后长,宽除以x,y取最小值,就是能分的个数。

c++:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,x,y,l;
    cin>>a>>b>>x>>y;
    l=__gcd(x,y);
    x/=l,y/=l;
    cout<<min(a/x,b/y)<<endl;
    return 0;
}

python:

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))

猜你喜欢

转载自blog.csdn.net/memory_qianxiao/article/details/82730080