题意:给定a, b, x, y; 求使c, d; 使c:d = x :y; 且c<=a, d<=b, 而且c, d尽量大。
先求最小倍数, 再用最小倍数乘 x, y;
1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <cmath>
5 using namespace std;
6
7 long long gcd(long long a, long long b)
8 {
9 return b?gcd(b, a%b):a;
10 }
11 int main()
12 {
13 long long a, b, x, y, tmp;
14 while(~scanf("%lld%lld%lld%lld", &a, &b, &x, &y))
15 {
16 tmp = gcd(x, y);
17 x /= tmp;
18 y /= tmp;
19 tmp = min(a/x, b/y);
20 printf("%lld %lld\n", x*tmp, y*tmp);
21 }
22 return 0;
23 }
sdut 2847 Monitor (思维题),布布扣,bubuko.com
时间: 2024-11-08 06:06:35