29602023-02-06 08:26:09bzsofiaFőzet készítéscpp11Accepted 50/50149ms5432 KiB
#include <iostream>
#include <vector>

using namespace std;

size_t i, j, a, b, t;

int gcd(int x, int y)
{
	while (x != 0 && y != 0)
	{
		if (x <= y) y %= x;
		else x %= y;
	}

	return x + y;
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	vector<vector<int>> dp(501, vector<int>(501, 0));

	for (i = 1; i < 32; ++i)
	{
		for (j = 1; j < 32; ++j)
		{
			if (gcd(i, j) == 1)
			{
				for (a = 500; a >= i; --a)
				{
					for (b = 500; b >= j; --b)
					{
						dp[a][b] = max(dp[a][b], dp[a - i][b - j] + 1);
					}
				}
			}
		}
	}

	cin >> t;
	for (i = 1; i <= t; ++i)
	{
		cin >> a >> b;
		cout << dp[a][b] << "\n";
	}
	return 0;
}
/*
3
4 4
2 3
2 2
*/
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/0148ms3628 KiB
2Accepted0/0148ms3820 KiB
3Accepted3/3148ms4056 KiB
4Accepted2/2146ms4448 KiB
5Accepted3/3148ms4656 KiB
6Accepted2/2148ms4912 KiB
7Accepted3/3148ms4956 KiB
8Accepted2/2148ms4836 KiB
9Accepted3/3148ms4984 KiB
10Accepted2/2148ms4936 KiB
11Accepted2/2148ms5000 KiB
12Accepted2/2148ms4888 KiB
13Accepted2/2148ms4776 KiB
14Accepted2/2148ms4900 KiB
15Accepted2/2149ms4988 KiB
16Accepted2/2148ms4984 KiB
17Accepted2/2148ms5112 KiB
18Accepted2/2149ms5188 KiB
19Accepted2/2149ms5428 KiB
20Accepted3/3148ms5432 KiB
21Accepted3/3148ms5412 KiB
22Accepted3/3149ms5408 KiB
23Accepted3/3148ms5408 KiB