U

1. Basic Arithmetic Operations

Easy

Problem Description

Read two integers AA and BB from standard input. Compute and print their sum, difference, product, quotient, and remainder.

If B=0B = 0, division and modulo operations are mathematically undefined; in such cases, output undefined for both quotient and remainder.

Input Format

A single line containing two space-separated integers AA and BB.

Output Format

Print exactly 5 lines:

  • •Line 1: A+BA + B (sum)
  • •Line 2: A−BA - B (difference)
  • •Line 3: A×BA \times B (product)
  • •Line 4: A/BA / B (integer quotient truncated toward zero) or undefined if B=0B = 0
  • •Line 5: A(modB)A \pmod B (remainder) or undefined if B=0B = 0
Example 1:
Input:
10 3
Output:
13
7
30
3
1
Explanation: 10 + 3 = 13, 10 - 3 = 7, 10 * 3 = 30. Integer division 10 / 3 = 3 with remainder 1.
Example 2:
Input:
7 0
Output:
7
7
0
undefined
undefined
Explanation: Divisor is 0, so quotient and remainder are undefined.
Example 3:
Input:
-15 4
Output:
-11
-19
-60
-3
-3
Explanation: -15 + 4 = -11, -15 - 4 = -19, -15 * 4 = -60. In integer truncation, -15 / 4 = -3, -15 % 4 = -3.
Constraints:
  • -10^5 <= A, B <= 10^5
  • Time complexity target: O(1)
  • Auxiliary space target: O(1)
Follow up:How would you handle arbitrarily large integers that exceed standard 64-bit limits?
1,180 Online