IRREV - Editorial

PROBLEM LINK:

Practice

EXPLANATION:

Observe that a fraction p/q would be irreducible only if gcd(p,q) \neq 1. If gcd is 1 then, p and q are coprime and hence irreducible, otherwise, we can always divide p and q by their common factors. Thus, we just need to check if gcd(p,q) is 1 then they are irreducible else not.

SOLUTION:

Setter's Soltuion
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long int ll;

    int main() {
        ll n;
        cin >> n;
        while (n--) {
            ll a, b;
            cin >> a >> b;
            if (__gcd(a, b) == 1) {
                cout << "YES\n";
            }
            else {
                cout << "NO\n";
            }
        }
        return 0;
    }
1 Like