#C12920. Dice Rolling Probability Simulation
Dice Rolling Probability Simulation
Dice Rolling Probability Simulation
You are given a positive integer n which represents the number of times to simulate rolling two six‐sided dice. In each simulation, you roll two dice and compute their sum. If the sum is either 7 or 11, it is considered a favorable outcome.
You must use the following linear congruential generator (LCG) to simulate dice rolls in order to achieve deterministic behavior across different languages. The LCG is defined as follows:
\[ X_{0} = n, \quad X_{i+1} = (1103515245 \times X_{i} + 12345) \mod 2^{31} \]
For each die roll, generate a random number using the LCG and then compute the die value as:
\[ die = (X \mod 6) + 1 \]
Perform two such die rolls per simulation. At the end, output three values separated by a space: the total number of rolls, the number of favorable outcomes (where the dice sum equals 7 or 11), and the probability (i.e. favorable outcomes divided by total rolls) formatted to 6 decimal places.
If the input number is not positive (i.e. n ≤ 0), print an error message: Error: Number of rolls must be positive
.
inputFormat
The input is read from standard input and consists of a single integer n (n > 0) which denotes the number of dice roll simulations.
outputFormat
The output should be printed to standard output. If n > 0, output three space-separated values: the total number of rolls (n), the number of favorable outcomes (where the sum is 7 or 11), and the probability of a favorable outcome formatted to 6 decimal places. If n ≤ 0, output the error message exactly as: Error: Number of rolls must be positive
.
1
1 0 0.000000
</p>