#P9441. Pirate Loot Division

    ID: 22593 Type: Default 1000ms 256MiB

Pirate Loot Division

Pirate Loot Division

After many daring raids, Cap'n Red and his crew of pirates decide to divide their loot in a peculiar way. The pirates stand in a circle ordered by a strict hierarchy. Cap'n Red starts the process by taking a fraction \(f\) of the total loot \(L\) and passes the remainder on to the next pirate. That pirate then takes the same fraction \(f\) of what remains and passes on the rest, and so on. When the last pirate takes his share, the remaining loot is passed back to Cap'n Red to start another round. This process continues indefinitely.

The total amount eventually received by the \(i^{th}\) pirate (where \(i = 0,1,\dots, n-1\) with Cap'n Red as \(i = 0\)) is given by the infinite series

[ share_i = \frac{f,(1-f)^i,L}{1 - (1-f)^n} \quad (0 \le i < n), ]

and it is required that each (share_i) is an integer.

Your task is: Given the number of pirates \(n\) and the total loot \(L\), find a rational fraction \(f = \frac{a}{b}\) in its simplest form (with \(0 < f < 1\)) such that every pirate’s share computed by the formula above is an integer. If there are multiple valid fractions, output the one with the smallest denominator \(b\) (and then the smallest numerator \(a\) if needed). If no such fraction exists, output -1.

Note: All formulas are given in \(\LaTeX\) format.

inputFormat

The input consists of a single line containing two integers \(n\) and \(L\) separated by a space. \(n\) represents the number of pirates and \(L\) is the total loot. You may assume that \(2 \le n \le 10\) and \(1 \le L \le 10^9\).

outputFormat

If a suitable fraction exists, output it in the format a/b where \(a\) and \(b\) are positive integers with \(\gcd(a,b)=1\). Otherwise, output -1.

sample

2 21
1/2