16C.Monitor

C. Monitor
time limit per test
0.5 second
memory limit per test
64 megabytes
input
standard input
output
standard output

Reca company makes monitors, the most popular of their models is AB999 with the screen size a × b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x: y became popular with users. That's why the company wants to reduce monitor AB999 size so that its screen sides ratio becomes x: y, at the same time they want its total area to be maximal of all possible variants. Your task is to find the screen parameters of the reduced size model, or find out that such a reduction can't be performed.

Input

The first line of the input contains 4 integers — abx and y (1 ≤ a, b, x, y ≤ 2·109).

Output

If the answer exists, output 2 positive integers — screen parameters of the reduced size model. Output 0 0 otherwise.

Examples
input
800 600 4 3
output
800 600
input
1920 1200 16 9
output
1920 1080
input
1 1 1 2
output
0 0

题意的屏幕是不能倒转的,不符合常理


#include<cstdio>
int gcd(int a,int b)
{
	if(b==0)
	{
		return a;
	}
	return gcd(b,a%b);
}
int min(int a,int b)
{
	return a<b?a:b;
}
int main()
{
	int a,b,x,y;
	while(~scanf("%d%d%d%d",&a,&b,&x,&y))
	{
		int width=0,height=0;
		int temp=gcd(x,y);
		x/=temp;y/=temp;

		int fold=min(a/x,b/y);
		if(fold>0)
		{
			width=fold*x;height=fold*y;
		}
		printf("%d %d\n",width,height);
	}
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值