Description
有一个长宽分别为 a,b 的屏幕,要修改其为长宽比为 x:y 的(需保证长宽均为正整数),问修改后最大规格屏幕的长宽
Input
四个整数 a,b,x,y(1≤a,b,x,y≤2⋅109)
Output
输出修改后屏幕的长宽,如果不存在合法方案则输出 0 0
Sample Input
800 600 4 3
Sample Output
800 600
Solution
水题,注意把比例化为最简再处理
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=100001;
int gcd(int a,int b)
{
return b?gcd(b,a%b):a;
}
int main()
{
int a,b,x,y;
while(~scanf("%d%d%d%d",&a,&b,&x,&y))
{
int g=gcd(x,y);
x/=g,y/=g;
int t=min(a/x,b/y);
printf("%d %d\n",t*x,t*y);
}
return 0;
}