luogu#P5179. Fraction

Fraction

Problem Description

You are given four positive integers a,b,c,da,\,b,\,c,\,d. Find a fraction pq\frac{p}{q} in lowest terms such that ab<pq<cd\frac{a}{b} < \frac{p}{q} < \frac{c}{d}.

If there are multiple solutions, output the one with the smallest qq. If there are still multiple solutions, output the one with the smallest pp.

Input Format

This problem contains multiple test cases. There are several lines, and each line contains four positive integers, which are a,b,c,da,b,c,d for one test case.

Output Format

For each test case, output one line. If the answer is pq\frac{p}{q}, print it in the format p/q.

1 3 1 2
2 1 3 1
2 1 4 1
1000 1001 1001 1002

2/5
5/2
3/1
2001/2003

Hint

Test Point ID Number of Test Cases Constraints on a,b,c,da,b,c,d
131 \sim 3 100\leqslant 100
4104 \sim 10 500\leqslant 500 109\leqslant 10^9

The testdata guarantees that there exists at least one fraction in lowest terms that satisfies the condition.

Translated by ChatGPT 5