Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
                                                        C++ Programming
#include <cstdio>
long gcd(long x, long y){return (x == 0) ? y : gcd(y % x, x);} 
int main(){
    long a, b, x, y; scanf("%ld %ld %ld %ld", &a, &b, &x, &y);
    long g = gcd(x, y);
    x /= g; y /= g;
    long u(a / x), v(b / y);
    long factor = (u < v) ? u : v;
    printf("%ld %ld\n", factor * x, factor * y);
    return 0;
}Input
                                                            800 600 4 3
                                                                                                                    
                                                    Output
                                                            800 600
                                                                                                                    
                                                    Demonstration
Codeforces Solution-C. Monitor-Solution in C, C++, Java, Python
