AIOC Banner

Problem: Mixed Fraction

Want to try solving this problem? You can submit your code online if you log in or register.


The problems in this set are designed to be more accessible to beginning coders. As a learning aid, walkthroughs discussing how to solve the problems in this set are available by clicking on this link. On completion of this problem set, students should know how to use a programming language to read and write files, perform simple arithmetic calculations, and write conditional (if) statements.

Mixed Fraction

Input File: mixin.txt
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.

Sample Input 1

22 6

Sample Output 1

3 4/6

Sample Input 2

49 7

Sample Output 2

7

Scoring

The score for each input file will be 100% if the correct answer is written to the output file and 0% otherwise.

 


Privacy statement
© Australian Mathematics Trust 2001-2019

Contact: training@orac.amt.edu.au
Page generated: 19 August 2019, 11:45am AEST