Mixed Fraction
Input File: mixin.txt
Output File: mixout.txt
Time Limit: 1 second
Output File: mixout.txt
Time Limit: 1 second
You are sitting at your computer surfing the internet when a chance forum post stirs memories of an idyllic past. There were so many different ways of representing rational numbers back then - percentages, decimals, and of course the mixed fraction. There was always something so wonderful about mixed fractions - the way they quickly told you how big the number was yet still conveyed the subtleties of the fractional part. Such elegance... You shed a silent tear for days long gone.
In this task you are given a fraction in the form n/d, where 1 <= d < n <= 1,000,000,000. Your task is to find the two integers a and b, where 0 <= b < d and ad + b = n. You do not need to (and shouldn't) simplify the fraction.
Input
A single line containing the integers n and d separated by a space.
Output
If b is not 0, print a single line in the format a b/d. Otherwise, print a.
Please click on the python code below:
No comments:
Post a Comment