Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/funksiya-kasrlar-yigindisi

Sum of two fractions

Easy 1000 ms 128 MB 33%
Share

Write a function AddFractions(a, b, c, d) that returns the sum of the fractions $\frac{a}{b}$ and $\frac{c}{d}$ as a reduced fraction — a string "numerator/denominator".

$$\frac{a}{b} + \frac{c}{d} = \frac{a * d + c * b}{b * d}$$

Example 1: AddFractions(1, 2, 1, 3) → "5/6"

Example 2: AddFractions(1, 4, 3, 4) → "1/1" — $\frac{1}{4} + \frac{3}{4} = 1$, a whole number is written as a fraction too.

Write only the function body.

Two fractions are added and reduced, the function returns the result

Input

One line with four positive integers $a$, $b$, $c$ and $d$ — the arguments of the function.

Output

The string returned by the function: the reduced fraction, e.g. 5/6.

Note

$1 \le a, b, c, d \le 10^{6}$

Examples

Input #1
1 2 1 3
Output #1
5/6
Input #2
1 4 3 4
Output #2
1/1

Sign in to submit a solution

Signing up is free and takes a minute.