#P5179. Find the Simplest Fraction Between Two Given Fractions

    ID: 18417 Type: Default 1000ms 256MiB

Find the Simplest Fraction Between Two Given Fractions

Find the Simplest Fraction Between Two Given Fractions

Given four positive integers (a,, b,, c,, d) representing two fractions (\frac{a}{b}) and (\frac{c}{d}) with (\frac{a}{b} < \frac{c}{d}), your task is to find an irreducible (simplest) fraction (\frac{p}{q}) such that

[ \frac{a}{b} < \frac{p}{q} < \frac{c}{d}, ]

where if multiple solutions exist, choose the one with the smallest denominator (q); if there is still a tie, choose the one with the smallest numerator (p).

You may assume that such a fraction always exists.

inputFormat

The input consists of a single line containing four space-separated positive integers: (a), (b), (c), (d). It is guaranteed that (\frac{a}{b} < \frac{c}{d}).

outputFormat

Output a single line representing the simplest fraction (\frac{p}{q}) (with no spaces) that satisfies the condition (\frac{a}{b} < \frac{p}{q} < \frac{c}{d}).

sample

1 2 3 4
2/3