Source Code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ios_base::sync_with_stdio(0);
    int t;
    cin>>t;
    while(t--) {
        ll n, a;
        cin>>n>>a;
        while(__gcd(n, a) > 1) n--;
        cout<<n<<endl;
    }
}
Copy
LCM and GCD RedNextCentury
GNU G++17
47 ms
468 KB
Accepted