loj#P6854. 「ICPC World Finals 2021」公平分配
「ICPC World Finals 2021」公平分配
Description
After sailing the Seven Seas and raiding many ships, Cap'n Red and his crew of fellow pirates are finally ready to divide their loot. According to ancient traditions, the crew stands in a circle ordered by a strict pirate hierarchy. Cap'n Red starts by taking a fraction of the loot and passing the remainder on to the next pirate. That pirate takes the same fraction of the loot left over by the previous pirate and passes the remainder on to the following pirate. Each pirate behaves in the same way, taking a fraction of what is left and passing on the rest. The last pirate in the hierarchy passes the remainder on to Cap'n Red, who starts another round of this "fair" division, and so on, indefinitely.
Fortunately, pirates in the 21st century can use a computer to avoid this lengthy process and constant nitpicking when the fraction does not exactly divide the loot at some step. You have been captured by the pirates and asked to come up with a suitable fraction . As an incentive, Cap'n Red has promised to leave you alive if you succeed.
The fraction needs to be a rational number strictly between and . It is not necessary that exactly divides the loot remaining at any step of the round-robin process described above. However, the total loot that would be assigned to each pirate by carrying out this process infinitely needs to be an integer.
Input
The input contains one line with two integers and , where () is the number of pirates including Cap'n Red and () is the total value of their loot.
Output
Output one line with two positive integers and , where as specified above. If there are multiple suitable fractions, choose one with the smallest . Among multiple suitable fractions with the same smallest choose the one with the smallest . If there is no suitable fraction, output impossible
instead and hope for mercy.
8 51000
1 2
6 91000
2 3
10 1000000000000000000
impossible