#P10802. Optimized COVID Group Testing

    ID: 12843 Type: Default 1000ms 256MiB

Optimized COVID Group Testing

Optimized COVID Group Testing

In Adam’s school, a new wave of COVID has forced the administration to instantly test all students using a saliva antigen test. However, testing every sample individually is time‐consuming. Adam proposes a clever method to reduce the number of tests: mix some samples together and test the pooled sample.

The test reagent is perfect – it always gives correct results, and any sample can be used in multiple tests. A pooled test returns negative if all of the samples in the pool are negative, or positive if at least one sample is positive.

For this problem, you are given an integer \( N \) (the number of samples, labeled from \(0\) to \(N-1\)) and a number \( P \) representing the independent probability that any given sample is positive.

Adam uses the following simple procedure:

  • Mix all \(N\) samples and perform one pooled test.
  • If the pooled test is negative, then all samples are negative and no further testing is needed.
  • If the pooled test is positive, test each sample individually to identify the positive ones.

The expected number of tests \( E \) for this procedure can be written in \( \LaTeX \) as follows:

[ E = (1-P)^N \cdot 1 + \Bigl(1 - (1-P)^N\Bigr) \cdot (N+1). ]

Your task is to compute and output the expected number of tests used in the procedure described above.

inputFormat

The input consists of a single line containing two values:

  • An integer \(N\) (\(1 \leq N \leq 10^5\)), the number of samples.
  • A floating-point number \(P\) (\(0 \leq P \leq 1\)), the probability that any one sample is positive.

Values are separated by spaces.

outputFormat

Output a single line containing the expected number of tests, rounded to 6 decimal places.

sample

1 0.5
1.500000