Problem Scenario

  Blog    |     January 29, 2026

The "Hidden QC Data" problem typically involves analyzing quality control data where defects are not directly observable but must be inferred from indirect evidence or patterns. Below is a step-by-step solution approach and example: A factory produces items, each with a unique ID (1 to 100). The defect status is hidden and determined by a rule:

  • Defective if the item ID is a prime number or a perfect square.
  • Non-defective otherwise.

Goal: Calculate the total number of defective items and the defect rate.


Solution Steps

  1. Identify Defective Items:

    • Prime numbers: IDs divisible only by 1 and themselves.
    • Perfect squares: IDs that are squares of integers (e.g., 1, 4, 9, 16, ..., 100).
  2. Generate IDs:

    IDs range from 1 to 100.

  3. Check Conditions:

    For each ID, check if it is prime or a perfect square.

  4. Count Defectives:

    Sum all IDs meeting either condition.

  5. Calculate Defect Rate:

    Defect rate = (Number of defective items) / (Total items).


Example Calculation

Defective IDs (1 to 100):

  • Prime numbers:
    2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97
    25 primes.

  • Perfect squares:
    1, 4, 9, 16, 25, 36, 49, 64, 81, 100
    10 squares.

  • Overlap: IDs that are both prime and perfect square:
    Only 1 (since 1 is a perfect square but not prime; no other ID satisfies both).
    No overlap to subtract.

Total Defective Items:

25 (primes) + 10 (squares) = 35 defective items.

Defect Rate:

35 defective / 100 total items = 35%.


Key Code Implementation (Python)

def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True
def is_perfect_square(n):
    root = int(n**0.5)
    return root * root == n
def find_defective_items(max_id=100):
    defectives = set()
    for id in range(1, max_id + 1):
        if is_prime(id) or is_perfect_square(id):
            defectives.add(id)
    return defectives
defective_ids = find_defective_items()
total_defective = len(defective_ids)
defect_rate = total_defective / 100  # Since max_id=100
print(f"Defective items: {total_defective}")
print(f"Defect rate: {defect_rate:.1%}")  # Output: 35.0%

Output

Defective items: 35
Defect rate: 35.0%

Explanation

  • Prime Check: Efficiently tests divisibility up to the square root of the ID.
  • Perfect Square Check: Uses integer square root to verify if an ID is a square.
  • Set Usage: Avoids double-counting IDs that meet both conditions (though none exist here).
  • Scalability: Works for any max_id (e.g., 1000, 10000).

This approach efficiently uncovers hidden defects by leveraging mathematical properties and systematic verification.


Request an On-site Audit / Inquiry

SSL Secured Inquiry