Five lines from the arithmetic trainer
Statement
An academy has one arithmetic trainer standing in it. When a student feeds this machine two natural numbers A and B in that order, the machine prints five lines on a slip of paper. The student then checks the answers worked out by hand against the printed slip.
The five lines the machine prints mean the following.
1) First line: A plus B 2) Second line: A minus B 3) Third line: A times B 4) Fourth line: the quotient of A divided by B 5) Fifth line: the remainder of A divided by B
The quotient on the fourth line drops everything below the decimal point. For example, 7 divided by 3 gives a quotient of 2 and a remainder of 1. When A divides evenly by B the remainder is 0, and even then the fifth line is not left empty, it prints 0.
Write a program that prints the five lines of the arithmetic trainer just as they are when the two numbers A and B are given.
For example, suppose A=7 and B=3 are fed in. The value on each line is then worked out as in the following table.
| Line | First | Second | Third | Fourth | Fifth |
|---|---|---|---|---|---|
| Meaning | Sum | Difference | Product | Quotient | Remainder |
| Calculation | 7 plus 3 | 7 minus 3 | 7 times 3 | 7 divided by 3, quotient | 7 divided by 3, remainder |
| Value | 10 | 4 | 21 | 2 | 1 |
So in this case 10, 4, 21, 2 and 1 are printed in that order over five lines.
Putting the results for other inputs into one table gives the following.
| A | B | First | Second | Third | Fourth | Fifth |
|---|---|---|---|---|---|---|
| 7 | 3 | 10 | 4 | 21 | 2 | 1 |
| 100 | 10 | 110 | 90 | 1000 | 10 | 0 |
| 10000 | 1 | 10001 | 9999 | 10000 | 10000 | 0 |
When B is 1, the quotient is the same as A and the remainder is 0.
Input and output examples
Example 1
Input
7 3
Output
10 4 21 2 1
Example 2
Input
100 10
Output
110 90 1000 10 0
Example 3
Input
10000 1
Output
10001 9999 10000 10000 0
Input
First the two numbers A and B that are fed into the arithmetic trainer are given on the first line, in that order, separated by one space. A and B are each natural numbers of at most 10,000. A is also larger than B. So the difference printed on the second line is always a natural number, and the quotient printed on the fourth line is 1 or more. B is never given as 0, so you do not have to handle a case where you cannot divide. This one line is the only line of input, and the space between the two numbers is a single space.
Output
Print the five values one per line, over five lines in all, in order. Print the sum on the first line, the difference on the second line, the product on the third line, the quotient on the fourth line and the remainder on the fifth line. Each line holds one number only, and no space is attached after the number. Even when the remainder is 0, print 0 on the fifth line.
Requirements
- The input is one line, and it holds two numbers separated by one space
- A and B are each natural numbers of at most 10,000, and A is larger than B
- The quotient drops everything below the decimal point
- The order of the five lines is sum, difference, product, quotient, remainder
- Even when the remainder is 0, print 0 on the fifth line
- You must write a program that reads from standard input and writes to standard output
- Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
- The languages you can use are Python and JavaScript
- The memory limit is 256MB. The browser does not measure it, it only states it
- The time limit is set by measuring the setter's reference solution on the same runtime
- On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
- The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
- There are 15 cases, and 3 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
- You have to pass all 15 cases to solve this.
Examples
3 public cases. Judging also uses hidden cases. You have to pass all 15 cases to solve this.
7 3
10 4 21 2 1
10000 1
10001 9999 10000 10000 0
100 10
110 90 1000 10 0
Solution
Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.
Submitting requires you to log in. Running against the public cases works without one.
You can test with 3 public cases. Submitting runs the hidden cases too.
People who solved this problem
The time shown is the time spent solving. Input reading time is outside the solver's control, so it is excluded. And since each device reports this value itself, we record which device measured it.
Log in and you can see the code once you solve this problem.
Log in and you can see the code once you solve this problem.