Source Code
#include <iostream>
using namespace std;
int gcd(int a, int b)
{
	if (a == 0)
		return b;
	return gcd(b % a, a);
}
int main()
{
	int t;
	cin >> t;
	while (t > 0)
	{
		int a, n;
		cin >> n >> a;
		int b = n;
		while (gcd(a, b) != 1)
			b--;
		cout << b << endl;
		t--;
	}
}
Copy
LCM and GCD Heromnxpw0
GNU G++17
26 ms
708 KB
Wrong Answer