QOJ.ac

QOJ

时间限制: 1 s 内存限制: 256 MB 总分: 100

#8151. Reliable Prophet

统计

You may have heard of Nostradamus. He was a Jewish Frenchman from the early 16th century and the most famous prophet in the world for the last 400 years. During his lifetime, he left behind "Les Prophéties," a collection of quatrains that has become an essential book for many occult enthusiasts studying future prophecies. Centuries later, the descendants of Nostradamus formed a mysterious group of prophets, each possessing outstanding predictive abilities. This mysterious group of prophets uses a collective strategy to improve the overall prediction accuracy of the group. Suppose there are $n$ prophets in the group, and they can each independently predict the outcome of a random event, such as whether a tossed coin lands heads or tails, with a prediction accuracy of $p$. Consider the following collective prediction strategy: use the prediction conclusion of more than half of these $n$ prophets as the collective prediction conclusion. For example, when predicting the result of a coin toss, if more than half of the prophets predict heads, the collective strategy predicts heads; otherwise, the collective strategy predicts tails. With this strategy, if $p = 81\%$, it can be calculated that for $n = 3$, the probability of the collective strategy being correct is $90.54\%$. Compared to a single prophet, the collective strategy significantly improves the prediction accuracy. In fact, when $p = 81\%$, as long as $n \ge 3$, the prediction accuracy of the collective strategy is no less than $90\%$.

In the Reliable Prophet problem, given the accuracy $p$ of a single prophet independently predicting a random event and the desired prediction accuracy $q$ to be achieved by the collective prediction strategy, calculate the minimum number of mutually independent prophets required to work together so that the prediction accuracy of the collective strategy is no less than $q$.

Implementation Details

Given the accuracy $p$ of a single prophet independently predicting a random event and the desired prediction accuracy $q$ to be achieved by the collective strategy, design an algorithm to calculate the minimum number of mutually independent prophets required to work together so that the prediction accuracy of the collective strategy is no less than $q$.

Input

There are $k$ test cases ($1 \le k \le 10$), with each line providing one test case. Each test case consists of two real numbers $p$ and $q$. Here, $p$ is the accuracy of a single prophet's prediction, and $q$ is the desired prediction accuracy to be achieved by the collective strategy.

Output

Output the minimum number of prophets required for each test case sequentially. Output one number per line. If the requirement cannot be met by any number of prophets, output -1.

Examples

Input 1

0.81 0.90
0.60 0.90
0.40 0.40
0.90 0.80
0.49 0.50

Output 1

3
41
1
1
-1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.