Pencil Factory
Time limit1sMemory limit128 MB
Count how many of k pencils get painted and varnished when each machine skips every (n+1)th and (m+1)th pencil, grouped into four categories.
- Level
Medium4 of 10
- Topics
- Math, Number theory, Implementation
- Solved
- No attempts yet
Problem
In a pencil factory, every unfinished pencil is processed in the same order: first it is painted by the painting machine, and immediately afterwards it is handed to the varnishing machine to be varnished. However, neither machine is properly tuned.
After the painting machine has painted pencils in a row, it leaves the very next pencil unpainted and then starts counting again. The varnishing machine behaves the same way: after varnishing pencils, it leaves the next pencil unvarnished and then continues.
Because of this, the factory ends up producing four kinds of pencils:
- pencils that are both painted and varnished (fully processed);
- pencils that are neither painted nor varnished;
- pencils that are painted but not varnished;
- pencils that are varnished but not painted.
Every pencil is unpainted and unvarnished before processing begins.
Given three natural numbers , , and (the number of unfinished pencils to be processed), write a program that computes the number of fully processed pencils and the number of pencils of each incomplete kind.
For example, if , , and , the processing can be illustrated by the table below (✓ means the operation was performed, ✗ means it was not).
As the table shows, only 12 of the 17 pencils are fully processed. One pencil (the 12th) is neither painted nor varnished, one pencil (the 6th) is painted but not varnished, and three pencils (the 4th, 8th, and 16th) are varnished but not painted.
Input
The first line contains three natural numbers , , and , separated by spaces.
It is guaranteed that , , and .
Output
Print four integers on a single line, in this order:
- the number of pencils that are both painted and varnished;
- the number of pencils that are neither painted nor varnished;
- the number of pencils that are painted but not varnished;
- the number of pencils that are varnished but not painted.
Print them in the order above, with a single space between adjacent numbers.