253302026-02-19 11:04:05PappMatyasFőzet készítéscpp17Accepted 50/50151ms1548 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

static int GreatestCommonDen(int a, int b)
{
    while (b != 0)
    {
        int r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int main()
{
    vector<vector<int>> dp;
    dp.resize(501, vector<int>(501,0));
    for (int x = 1; x < 32; x++)
    {
        for (int y = 1; y < 32; y++)
        {
            if (GreatestCommonDen(x, y) == 1)
            {
                for (int i = 500; i >= x; i--)
                {
                    for (int j = 500; j >= y; j--)
                    {
                        dp[i][j] = max(dp[i][j], dp[i - x][j - y] + 1);
                    }
                }
            }
        }
    }
    int a, b;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> a >> b;
        cout << dp[a][b] << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/0145ms1332 KiB
2Accepted0/0150ms1536 KiB
3Accepted3/3145ms1400 KiB
4Accepted2/2146ms1332 KiB
5Accepted3/3146ms1516 KiB
6Accepted2/2146ms1332 KiB
7Accepted3/3150ms1332 KiB
8Accepted2/2150ms1524 KiB
9Accepted3/3151ms1396 KiB
10Accepted2/2150ms1348 KiB
11Accepted2/2150ms1392 KiB
12Accepted2/2150ms1332 KiB
13Accepted2/2150ms1332 KiB
14Accepted2/2150ms1396 KiB
15Accepted2/2150ms1524 KiB
16Accepted2/2150ms1332 KiB
17Accepted2/2151ms1332 KiB
18Accepted2/2151ms1524 KiB
19Accepted2/2150ms1332 KiB
20Accepted3/3150ms1524 KiB
21Accepted3/3150ms1548 KiB
22Accepted3/3150ms1392 KiB
23Accepted3/3150ms1524 KiB