That set is a harmful set
Time limit3sMemory limit256 MB
For each rational a/b, print the smallest n from 0 to 10 whose stage set misses it, or -1 when all eleven contain it.
- Level
Medium5 of 10
- Topics
- Math, Simulation
- Solved
- No attempts yet
Problem
While studying set theory, Seunghyun ran into the following family of sets.
made no sense to him, so he planned two jobs. The first job picks a rational number and decides whether it belongs to . If it does not, the second job finds the set with the smallest subscript that fails to contain the number.
After doing this by hand a few times he got tired of it and decided to use a computer. Then he got tired of the coding too, so he handed the work to you, his junior. Stuck with the job, you decided to write an incomplete checker to play a trick on him.
If the answers look too strange he will not fall for it, so the output has to stay plausible. The program checks membership only for through , and if all eleven sets contain the number it declares the number to be in . Write that incomplete program.
Input
The first line contains the number of test cases .
Each of the next lines contains the numerator and the denominator of a rational number, separated by a space. (, )
Output
Print one line per test case.
If some set among through does not contain , print the smallest such subscript . If all eleven sets contain it, print -1.
Hint
, and .
belongs to but not to . belongs through and drops out at .
A number with numerator 0 lies in every set: take and every in the definition.
If is greater than 1, it already fails at , so the answer is 0.