|
U
Pro1. Basic Arithmetic Operations
Easy
Problem Description
Read two integers A and B from standard input. Compute and print their sum, difference, product, quotient, and remainder.
If B=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 A and B.
Output Format
Print exactly 5 lines:
- •Line 1: A+B (sum)
- •Line 2: A−B (difference)
- •Line 3: A×B (product)
- •Line 4: A/B (integer quotient truncated toward zero) or
undefinedif B=0 - •Line 5: A(modB) (remainder) or
undefinedif B=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^5Time 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
Code
|Loading Code Editor...
SavedLn 1, Col 1
input =
Sandboxed Engine
Ctrl+Enter = Run | Ctrl+Shift+Enter = Submit