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.
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.
A single line containing the integers n and d separated by a space.
If b is not 0, print a single line in the format a b/d. Otherwise, print a.
The score for each input file will be 100% if the correct answer is written to the output file and 0% otherwise.
© Australian Mathematics Trust 2001-2023
Page generated: 3 June 2023, 3:00pm AEST