Fraction Action
InterviewTime limit1sMemory limit128 MB
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.