#P11045. [蓝桥杯 2024 省 Java B] 最优分组

[蓝桥杯 2024 省 Java B] 最优分组

Problem Description

Xiaolan opened a pet shop. Recently, an X virus has been spreading among animals. To be safe, Xiaolan plans to buy test kits to test his pets for infection.

To reduce the number of test kits used, Xiaolan came up with a good idea: evenly divide NN pets into several groups, so that each group has exactly KK pets. For each group, take samples from the pets in the same group, mix them, and use one test kit to test. If the test result is negative, it means none of the pets in the group is infected with the X virus. If it is positive, then all KK pets in the group need to be tested individually, which will consume an additional KK test kits (when K=1K=1, there is no need for another individual test, because there is only one pet in the group, and one test is enough to confirm the result).

Now we know that the probability that Xiaolan’s pets are infected is pp. What value should KK take so that the expected number of test kits consumed is minimized? If there are multiple answers, output the smallest KK.

Input Format

The first line contains an integer NN.

The second line contains a floating-point number pp.

Output Format

Output one line containing an integer KK as the answer.

1000
0.05
5

Hint

【Test Case Scale and Constraints】

For 30%30\% of the test cases: 1N101\leq N\leq 10.

For 60%60\% of the test cases: 1N10001\leq N\leq 1000.

For 100%100\% of the test cases: 1N1061\leq N\leq 10^60p10\leq p\leq 1

Translated by ChatGPT 5