solution.cpp 650 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#include <stdio.h>

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int main()
{
    // 这是屏幕上显示的那个分数 a/b
    int a = 7;
    int b = 13;

    int m, n;
    int max_a = 0;
    int max_b = 1;

    for (n = 100; n > 1; n--)
    {
        for (m = n - 1; m >= 1; m--)
        {
            if (m * b < a * n && gcd(m, n) == 1)
            {
                if (m * max_b > n * max_a)
                {
                    max_a = m;
                    max_b = n;
                    break;
                }
            }
        }
    }

    printf("%d/%d\n", max_a, max_b);
    return 0;
}