PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000387. Phép tính số hữu tỉ (Rational Arithmetic)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Phép tính số hữu tỉ (Rational Arithmetic)

Rational Arithmetic

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

Given two rational numbers a/ba/b and c/dc/d and an operation +, -, *, or /, compute the exact result. Output the reduced fraction p/qp/q, where q>0q>0 and gcd⁡(∣p∣,q)=1\gcd(|p|,q)=1.

Division appears only when the second fraction is nonzero. For a zero result, print 0 / 1.

PHOJ convention: Each .in file contains exactly one arithmetic expression, with no leading count. The original Kattis format may contain multiple expressions; those are split into separate PHOJ test files. The bounds below are those of this PHOJ Extended version.

Input

One line with five fields a b op c da\ b\ op\ c\ d, where op belongs to +, -, *, /.

Output

A single line p / q, using one space around the slash, where qq is positive and the fraction is reduced.

Subtasks

  • Subtask 1 (20 points): ∣a∣,∣c∣≤100|a|,|c|\le100 and 1≤∣b∣,∣d∣≤1001\le|b|,|d|\le100.

  • Subtask 2 (30 points): ∣a∣,∣c∣≤106|a|,|c|\le10^6 and 1≤∣b∣,∣d∣≤1061\le|b|,|d|\le10^6.

  • Subtask 3 (50 points): ∣a∣,∣c∣≤109|a|,|c|\le10^9 and 1≤∣b∣,∣d∣≤1091\le|b|,|d|\le10^9.

In every subtask, op / guarantees c≠0c\ne0.

Examples

Example 1

Input

1 2 + 1 3

Output

5 / 6

Explanation

12+13=3+26=56\frac12+\frac13=\frac{3+2}{6}=\frac56.

Example 2

Input

-6 8 / 3 -4

Output

1 / 1

Explanation

Both input fractions equal −3/4-3/4, so their quotient is 11, printed as 1 / 1.

Example 3

Input

7 9 - 7 9

Output

0 / 1

Explanation

The difference is zero. Its normalized representation has denominator 11.