16C

来源:互联网 发布:centos kvm 多主机 编辑:程序博客网 时间:2024/06/05 19:00

#include<bits/stdc++.h>using namespace std;int gcd(int a,int b){    return !b?a:gcd(b,a%b);}int main(){    int a,b,x,y,t,m;    while(cin>>a>>b>>x>>y)    {        t=gcd(x,y);        x/=t;        y/=t;        m=min(a/x,b/y);        cout<<x*m<<" "<<y*m<<endl;    }    return 0;}

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

题意:输入一个a*b尺寸的显示器,让你把它改成x*y的显示器。也就是a/b=x/y,分数形式那种等于。

题解:x,y的范围比较大,把x:y比例gcd最简化,然后用a除以最简化的x和b除以最简化的y,取最小值。再用x*min值,y*min值就是答案。


原创粉丝点击