18642022-12-06 09:59:27kdbFőzet készítéscpp11Accepted 50/50152ms6212 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <chrono>
using namespace std;


int lnko(int a, int b)
{
	while (a!=0 && b != 0)
	{
		if (a > b)
		{
			a %= b;
		}
		else
		{
			b %= a;
		}
	}
	return a + b;
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin >> n;
	vector<vector<int>> vec(501, vector<int>(501, 0));
	
	for (size_t i = 1; i < 32; i++)
	{
		for (size_t j = 1; j < 32; j++)
		{
			if (lnko(i, j) == 1)
			{
				for (size_t x = 500; x > i-1; x--)
				{
					for (size_t y = 500; y > j-1; y--)
					{
						vec[x][y] = max(vec[x][y], vec[x - i][y - j] + 1);
					}
				}
			}
		}
	}
	for (size_t i = 0; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		cout << vec[a][b] << endl;
	}
	return 0;
}
/*
3
4 4
2 3
2 2
*/
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/0148ms3688 KiB
2Accepted0/0150ms3932 KiB
3Accepted3/3148ms4080 KiB
4Accepted2/2148ms4288 KiB
5Accepted3/3148ms4364 KiB
6Accepted2/2148ms4588 KiB
7Accepted3/3151ms4796 KiB
8Accepted2/2150ms5160 KiB
9Accepted3/3150ms5084 KiB
10Accepted2/2150ms5152 KiB
11Accepted2/2150ms5272 KiB
12Accepted2/2150ms5496 KiB
13Accepted2/2149ms5716 KiB
14Accepted2/2150ms5712 KiB
15Accepted2/2150ms5620 KiB
16Accepted2/2152ms5688 KiB
17Accepted2/2151ms5684 KiB
18Accepted2/2151ms5812 KiB
19Accepted2/2149ms5888 KiB
20Accepted3/3151ms5888 KiB
21Accepted3/3150ms6016 KiB
22Accepted3/3150ms6096 KiB
23Accepted3/3149ms6212 KiB