1. Abridged Problem Statement

Given an integer N (1 ≤ N ≤ 10) and a list of N positive integers (each up to 10^9), determine for each number whether it is "nearly prime," i.e., it can be written as the product of exactly two primes (primes may coincide). For each input number, print "Yes" if it is nearly prime, otherwise print "No."

2. Detailed Editorial

Definition
A positive integer X is called nearly prime if X = p1 * p2 for some primes p1, p2 (they may be equal). Equivalently, the prime-factorization of X has exactly two prime factors counting multiplicity.

Approach
We need to test each input number A for the total count of prime factors (with multiplicity). If that count equals exactly 2, we answer "Yes"; otherwise, "No."

Step-by-step solution
1. Read N and the array A[0…N–1].
2. For each A[i]:
   a. Initialize a counter c = 0.
   b. For each potential divisor d from 2 up to sqrt(A[i]):
      – While d divides A[i]:
         • Increment c by 1.
         • Divide A[i] by d (A[i] /= d).
   c. After the loop, if A[i] > 1 then it is a remaining prime factor, so increment c by 1.
   d. If c == 2, print "Yes"; otherwise, print "No."

Complexity
Each number up to 10^9 requires trial divisions up to √A ≈ 3·10^4. Since N ≤ 10, the total number of division attempts is O(N√A) ≈ 3·10^5 in the worst case, which is well within the time limit.

Edge Cases
– A prime number has c == 1 → "No."
– A perfect square of a prime (e.g., 4, 9, 25) has c == 2 → "Yes."
– A product of three or more primes (e.g., 30 = 2·3·5) has c ≥ 3 → "No."
– 1 has c == 0 → "No."

3. C++ Solution

```cpp
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int n;
vector<int> a;

void read() {
    cin >> n;
    a.resize(n);
    cin >> a;
}

void solve() {
    // A nearly prime number is a product of exactly two primes. For each value
    // trial-divide out prime factors counting them with multiplicity; the
    // number is nearly prime iff the total count of prime factors is exactly 2.

    for(int i = 0; i < n; i++) {
        int x = a[i];
        int cnt = 0;
        for(int d = 2; d * 1ll * d <= x; d++) {
            while(x % d == 0) {
                cnt++;
                x /= d;
            }
        }

        if(x != 1) {
            cnt++;
        }

        cout << (cnt == 2 ? "Yes" : "No") << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}
```

4. Python Solution with Detailed Comments

```python
import math
import sys

def is_nearly_prime(x):
    """
    Return True if x has exactly two prime factors (with multiplicity).
    """
    count = 0
    # Trial divide up to sqrt(x)
    d = 2
    while d * d <= x:
        # While d divides x, count the factor and divide it out
        while x % d == 0:
            count += 1
            x //= d
            # Early termination if we exceed 2 factors
            if count > 2:
                return False
        d += 1 if d == 2 else 2  # After 2, test only odd divisors

    # If something remains >1, it is a prime factor
    if x > 1:
        count += 1

    return (count == 2)

def main():
    data = sys.stdin.read().split()
    n = int(data[0])
    nums = list(map(int, data[1:]))

    for x in nums:
        print("Yes" if is_nearly_prime(x) else "No")

if __name__ == "__main__":
    main()
```

5. Compressed Editorial

- A number is nearly prime iff it has exactly two prime factors (counted with multiplicity).
- For each input x (≤1e9), trial-divide by d from 2 to √x, counting factors.
- If after the loop x>1, count++.
- If total count ==2 → "Yes"; else → "No."
- Complexity per number: O(√x), overall O(N√x) with N≤10.
