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).  
      – If at any point c > 2, we can break early (optional optimization).  
   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. Provided C++ Solution with Line-by-Line Comments

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

const int MAXN = (1 << 10);  // Maximum N is up to 10, so we allocate 2^10 = 1024 just out of convenience

int n;            // Number of input values
int a[MAXN];      // Array to store the input values

// Read input values into n and a[]
void read() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
}

// Main solve function
void solve() {
    // Process each number in the array
    for (int i = 0; i < n; i++) {
        int x = a[i];  // Work on a copy so we don't lose the original
        int c = 0;     // Counter for total prime factors (with multiplicity)

        // Trial divide by all integers from 2 up to sqrt(x)
        for (int d = 2; 1LL * d * d <= x; d++) {
            // While d is a prime factor, divide it out
            while (x % d == 0) {
                c++;       // One more prime factor found
                x /= d;    // Remove factor d from x
                if (c > 2) // Optional early exit if count already exceeds 2
                    break;
            }
            if (c > 2)
                break;
        }

        // If after removing small factors x > 1, then x itself is a prime factor
        if (x > 1) {
            c++;
        }

        // If exactly two prime factors in total → nearly prime
        if (c == 2) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    read();   // Read inputs
    solve();  // Compute and print answers
    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.