Not able to find edge case, Please help!

Question - DIV3 D

My Solution


#include <bits/stdc++.h>
using namespace std;

long long int firstPrime(long long int n)
{
    if(n%2 == 0) return 2;
    else
    {
        for(long long int i = 3; i <= sqrt(n); i = i+2)
        {
            if(n%i == 0) return i;
        }
    }
    return n;
}
long long int numOfPF(long long int n)
{
    long long int counter = 0;
    while(n%2 == 0)
    {
        counter++;
        n = n/2;
    }

    for(long long int i = 3; i <= sqrt(n); i = i + 2)
    {
        while(n%i == 0)
        {
            counter++;
            n = n/i;
        }
    }
    if(n > 2) counter++;
    return counter;
}
void solve(void)
{
    long long int a, b, k;
    cin >> a >> b >> k;

    long long int base = __gcd(a, b);
    base = firstPrime(base);
    a = a/base;
    b = b/base;

    long long int num = numOfPF(a) + numOfPF(b);
    // cout << num << endl;

    if(k == 1)
    {
        if((a%b == 0 || b%a == 0) && (a != b)) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    else if(num >= k) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main()
{
    long long int ntc;
    cin >> ntc;

    for(long long int i = 0; i < ntc; i++)
    {
        solve();
    }
    return 0;
}

I don’t know what’s wrong with my code. It is giving WA on test case 2’s 1012th query. As this code is giving the correct output for many queries, so I guess the logic is correct and I am missing some edge cases.