Source Code
#include<iostream>

long long gcd(long long a, long long b) { return !b? a: gcd(b, a % b); }

using namespace std;

int main() {

    int TC = 1; cin >> TC;
    while(TC--) {

        long long n, a; cin >> n >> a;

        while(gcd(a, n) != 1) n--;

        cout << n << "\n";

    }

    return 0;

}
Copy
LCM and GCD MahmoudKhalid
GNU G++17
60 ms
448 KB
Accepted