Log inSign up
Problems / B004

Five lines from the arithmetic trainer

100 ptsCases 15Set by dongbinna
Added October 30.
2 solved2 attempted2 submissionssolvers took 1.0 tries on average

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.

LineFirstSecondThirdFourthFifth
MeaningSumDifferenceProductQuotientRemainder
Calculation7 plus 37 minus 37 times 37 divided by 3, quotient7 divided by 3, remainder
Value1042121

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.

ABFirstSecondThirdFourthFifth
731042121
10010110901000100
10000110001999910000100000

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.
Read the requirements carefully before solving. Tampering with the grading to make a submission look like a pass can get you sanctioned if caught. The code you submit is published on the leaderboard along with the result.

Examples

3 public cases. Judging also uses hidden cases. You have to pass all 15 cases to solve this.

Input
Expected output
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.

0 chars1 lineMemory 256MB (recorded only)Reference 2.0ms

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.

1ostenhun15ms99 charsPythonWindows NT 10.0 / Chrome/154.0.0.0 / 12코어 / 32GB

Log in and you can see the code once you solve this problem.

2bampal247ms264 charsPythonLinux / Chrome/158.0.8127.18 / 2코어 / 16GB

Log in and you can see the code once you solve this problem.