No.2972 Probabilistic Primality Test
タグ : / 解いたユーザー数 49
作問者 : 👑
Moss_Local
Problem Statement
Probabilistic Primality Test Lover Bot is a bot that loves probabilistic primality tests.
Probabilistic Primality Test Lover Bot Lover Bot is a bot that loves Probabilistic Primality Test Lover Bot. Of course, the $2$ bots are different entities.
Now consider the following problem:
You are given as input a positive integer $N$ and non-negative integers $P, Q$ not exceeding $100$.
When a positive integer is fed to Probabilistic Primality Test Lover Bot, it behaves as follows:
- If the positive integer it read is prime, it answers
Yeswith probability $P$ % and answersNowith probability $(100 - P)$ %.- If the positive integer it read is not prime, it answers
Nowith probability $Q$ % and answersYeswith probability $(100 - Q)$ %.Probabilistic Primality Test Lover Bot Lover Bot chose a positive integer $n$ at random from all positive integers not exceeding $N$ (so that every positive integer is equally likely to be chosen) and fed it to Probabilistic Primality Test Lover Bot. You do not know the value of $n$, but you have confirmed only that Probabilistic Primality Test Lover Bot answered
Yes.Given the above information, find the probability that $n$ is prime. (Hereafter, this value is called the answer to this problem.)
At the beginning of the input, a positive integer $T$ is given. Then, answer $T$ problems.
Input
The input is given from standard input in $1 + T$ lines in the following format:
- On line $1$, $T$ is given, separated by half-width spaces.
- For each positive integer $t$ not exceeding $T$, the input for the $t$-th problem is given on line $1 + t$.
$T$ ($1$ 個目の問題に対する入力) $\vdots$ ($T$ 個目の問題に対する入力)
For each positive integer $t$ not exceeding $T$, the input for the $t$-th problem is given in the following format:
- $N, P, Q$ are given separated by half-width spaces in $1$ line (line $1 + t$ of the whole input).
$N$ $P$ $Q$
The unknown $n$ in each problem is not given in the input.
Constraints
The input satisfies the following constraints:
- $T$ is an integer satisfying $1 \leq T \leq 10^5$.
- For each positive integer $t$ not exceeding $T$, letting $N, P, Q$ be the input for the $t$-th problem,
- $N$ is an integer satisfying $1 \leq N \leq 10^5$.
- $P$ is an integer satisfying $0 \leq P \leq 100$.
- $Q$ is an integer satisfying $0 \leq Q \leq 100$.
- Either $N > 1$ and $0 < P$, or $Q < 100$.
Output
For each positive integer $t$ not exceeding $T$, print the answer to the $t$-th problem in decimal notation on line $t$.
Print a newline at the end.
Note that this problem accepts answers with decimal error. Your answer is judged correct if either its absolute error or its relative error from the approximation of the exact answer to $10$ decimal places is at most $10^{-5}$:
Here, the approximation of a real number $x$ to $10$ decimal places means the largest real number that has a finite decimal representation with at most $10$ digits after the decimal point and does not exceed $x$.
Also, due to judge limitations, each output must be less than $500$ digits long.
Sample
Sample 1
Input
1 1 90 80
Output
0
Regardless of the fact that Probabilistic Primality Test Lover Bot answered Yes, the probability that a positive integer $n$ not exceeding $N = 1$ is prime is $0$. Because of the error tolerance of this problem, outputs such as
0.00
and
-0.00001
are also accepted. Since $T = 1$ here, this completes the answers to all the problems.
Sample 2
Input
1 2 100 0
Output
0.5
Since $P = 100$ and $Q = 0$, Probabilistic Primality Test Lover Bot returns Yes no matter what positive integer it reads. Therefore, the fact that Probabilistic Primality Test Lover Bot answered Yes gives no information about whether $n$ is prime. Thus, the desired value is nothing but the probability that $n$ is the prime $2$ when $n$ is chosen at random from all positive integers $\{1,2\}$ not exceeding $N = 2$, which is $0.5$.
Since $T = 1$ here, this completes the answers to all the problems.
Sample 3
Input
2 3 100 100 4 50 50
Output
1 0.5
First, we answer problem number $1$. Here $P = 100$ and $Q = 100$, so Probabilistic Primality Test Lover Bot always correctly determines whether the positive integer it read is prime. Since the answer of Probabilistic Primality Test Lover Bot was Yes, the probability that $n$ is prime is $1$.
Next, we answer problem number $2$. Here $P = 50$ and $Q = 50$, so whether the answer of Probabilistic Primality Test Lover Bot is Yes or No is determined at random independently of $n$. Therefore, the fact that Probabilistic Primality Test Lover Bot answered Yes gives no information about whether $n$ is prime. Thus, the desired value is nothing but the probability that $n$ is one of the primes $2,3$ when $n$ is chosen at random from all positive integers $\{1,2,3,4\}$ not exceeding $N = 4$, which is $0.5$.
Since $T = 2$ here, this completes the answers to all the problems.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。