This page is still under construction.

Parts of this page are still being built. What you see may change.

Fraction Action

Interview

Time limit1sMemory limit128 MB

Summary
Reduce a numerator and denominator to simplest form, then print it as a whole number, a proper fraction, or a mixed number.
Level

Easy2 of 10

Topics
Math, Number theory, Implementation
Solved
No attempts yet

Problem

Many advanced calculators have a feature that automatically simplifies fractions for you.

You are given a non-negative integer (the numerator) and a positive integer (the denominator). Write a program that outputs the fraction in its simplest form. Simplest form means the fraction cannot be reduced any further, and the numerator of the fractional part is less than the denominator.

The output rules are:

  • If the value is a whole number, print just that whole number.
  • If there is both a whole part and a proper-fraction part, print it as a mixed number in the form whole numerator/denominator.
  • If the whole part is 0, print only the proper fraction numerator/denominator.

You may assume that every given numerator and denominator forms a valid fraction.

Input

The first line contains the numerator (a non-negative integer). The second line contains the denominator (a positive integer).

Output

Print the fraction in its simplest form on a single line.

Examples4

  1. Example 1

    Input
    28
    7
    
    Expected output
    4
    
  2. Example 2

    Input
    13
    5
    
    Expected output
    2 3/5
    
  3. Example 3

    Input
    0
    7
    
    Expected output
    0
    
  4. Example 4

    Input
    55
    10
    
    Expected output
    5 1/2