Source Code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define fixed(n) cout << fixed << setprecision(n);
#define mod 1000000007
#define cin(v) for (auto&i:v) cin >> i;
#define cout(v) for (auto&i:v) cout << i << " ";
#define ceil(n,m) (n / m + (n%m != 0))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

void lil_codi_vert(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    #endif
}

//int dx[] = {1, 1, 1, 0, 0, -1, -1, -1};
//int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};



int main(){
    lil_codi_vert();
    ll t; cin >> t;
    while(t--){
        ull n, a; cin >> n >> a;
        if(a == 1) cout << n * a << "\n";
        else{
            while(gcd(n,a) != 1) n--;
            cout << n << "\n";
        }
    }
    return 0;
}
Copy
LCM and GCD aboelsoudJr
GNU G++17
14 ms
512 KB
Accepted