2 条题解

  • 1
    @ 2023-8-14 12:08:26
    #include <cstdio>
    #include <iostream>
    using namespace std;
    int a, b, l, ka = 1000001, kb = 1;
    double c;
    inline int gcd(int a, int b) {
    	return !b ? a : gcd(b, a % b);
    } 
    int main() {
    	freopen("ratio.in", "r", stdin);
    	freopen("ratio.out", "w", stdout);
    	scanf("%d%d%d", &a, &b, &l);
    	c = double(a) / double(b);
    	for (int i = 1; i <= l; i++)
    	    for (int j = 1; j <= l; j++)
    	        if (gcd(i, j) == 1 && (double)i / (double)j >= c)
    	        	if ((double)i / (double)j < (double)ka / (double)kb)
    	        	    ka = i, kb = j;
    	printf("%d %d", ka, kb);
    	return 0;
    }
    

    信息

    ID
    453
    时间
    1000ms
    内存
    256MiB
    难度
    6
    标签
    (无)
    递交数
    59
    已通过
    20
    上传者