Source Code
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define x           first
#define y           second
#define all(v)      v.begin(),v.end()
#define clr(v,d)    memset(v,d,sizeof(v));

const int N = 1e5 + 10;

const ll mod = 1e9 + 7;

int n , a[N];


int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);



    int t = 1 ;
    cin >> t ;
    while(t--)
    {
        ll n , m;
        cin >> n >> m;
        while(__gcd(n,m) > 1) n--;
        cout << n << "\n" ;
    }

    return 0;
}
Copy
LCM and GCD MuhammadHassan
GNU G++17
17 ms
508 KB
Accepted